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对象加载的输入流关闭异常");
    }
    }
    }
    }

  • 相关阅读:
    //删除字符串值的某个值
    disabled和readonly 的用法区别
    Js判断为空或不是对象或是否相等
    1.类型分析:
    多行内容放到一行中(内容的合并)
    sql split
    sql修改列名
    对oracle数字类型的研究
    kettle--组件(3)--行转列
    kettle--组件(2)--计算器
  • 原文地址:https://www.cnblogs.com/ouyy/p/6826011.html
Copyright © 2011-2022 走看看