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

  • 相关阅读:
    iOS内购开发(也许是最全的介绍)
    React Native 学习(三)之 FlexBox 布局
    React Native组件解析(二)之Text
    苹果开发者账号(个人、公司、企业)的区别
    React Native学习(二)之View
    搭建React Native开发环境
    iOS 提交AppStore不出现构建的版本
    Python使用Mysql过程中一些错误
    数据分析之漏斗模型
    项目管理之敏捷方式(我们的方式)
  • 原文地址:https://www.cnblogs.com/ouyy/p/6826011.html
Copyright © 2011-2022 走看看