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();
}
}
读取java配置文件
最新推荐文章于 2024-04-05 11:20:52 发布