zoukankan      html  css  js  c++  java
  • 读取.properties的内容1

      属性文件方便于项目进行更改,在项目开发中用的也是非常的普遍,在这里就把属性文件的读取通过代码进行一个小结:

    package com.oyy.test;

    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Iterator;
    import java.util.Locale;
    import java.util.Properties;
    import java.util.ResourceBundle;

    public class T3 {
    public static void main(String[] args) throws IOException {
    //无序读取属性文件的key和value
    Properties prop = new Properties();
    InputStream in = null;
    try {
    // 读取属性文件a.properties
    in = new BufferedInputStream(new FileInputStream("E:\Workspaces\MyEclipse 8.5\threeFormatsOfTheHttpRequest\src\system.properties"));
    prop.load(in); // /加载属性列表
    //输出key为userName所对应的值:getTokenUser1
    // System.out.println(prop.get("userName"));
    Iterator<String> it = prop.stringPropertyNames().iterator();
    while (it.hasNext()) {
    //获取属性文件的key
    String key = it.next();
    //获取属性文件的value
    String value = prop.getProperty(key);
    //此时可以将属性文件放入对象或者map集合中 TODO

    System.out.println(key + ":" + value);
    }
    // // 保存属性到b.properties文件,如果属性文件b.properties不存在,则会新生成一个属性文件
    // FileOutputStream oFile = new FileOutputStream("E:\dom4j\b.properties", true);// true表示追加打开
    // prop.setProperty("phone", "10086");
    // prop.store(oFile, "The New properties file");
    // oFile.close();
    }
    catch (Exception e) {
    System.out.println(e);
    }finally{
    try {
    in.close();
    } catch (IOException e) {
    e.printStackTrace();
    //logger.error("属性类Properties对象加载的输入流关闭异常");
    }
    }
    }
    }

  • 相关阅读:
    中国行业应用软件领域恶性循环的原因是什么?【转载】
    UED之开新窗口
      关于周华健,我觉得有那么几个时期:转
    投影
    undo自动调优介绍
    (原)Oracle事务与Undo段的分配过程
    数据所在的数据块实验
    Oracle 检查点队列与增量检查点
    GC Buffer Busy Waits处理
    如何找出Oracle instance中当前打开游标open cursor的总数?
  • 原文地址:https://www.cnblogs.com/ouyy/p/6826011.html
Copyright © 2011-2022 走看看