读取java配置文件

来源:互联网 发布:阿里云邮箱企业版pc端 编辑:程序博客网 时间:2024/06/05 02:23
package com.io.study;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.util.Properties;public class TestProperties {//创建配置文件Properties pp = new Properties();/* * 向配置文件中写入内容 */public void pushPro(){FileOutputStream fos = null;pp.setProperty("1", "你是谁?");pp.setProperty("2", "who are you?");try {fos = new FileOutputStream("d:/test.properties");pp.store(fos, "test");} catch (Exception e) {e.printStackTrace();}System.out.println("store successful!");}/* *读取配置文件中的信息  */public void getPro(){FileInputStream fis = null;try {fis = new FileInputStream("d:/test.properties");pp.load(fis);} catch (Exception e) {e.printStackTrace();}System.out.println(pp.getProperty("1"));System.out.println(pp.getProperty("2"));}/* * 方法入口 */public static void main(String[] args) {TestProperties tp = new TestProperties();//tp.pushPro();tp.getPro();}}
原创粉丝点击