properties 与 IO

public class PrintDemo01 {
public static void main(String[] args) throws Exception{
//需求: 使用properties 把键值对信息存入到属性文件中去
Properties properties = new Properties();
properties.setProperty("admin","123456");
properties.setProperty("milan","543211");
properties.setProperty("smith","520133");

//参数一 保存字符输出流管道
//参数二 保存心得
properties.store(new FileWriter("E:\\idea_java_project\\io_project\\src\\Properties.properties"),
"");

}
}
取(读)
//需求: 使用properties 读取属性文件中的键值对信息(读取)
Properties properties = new Properties();

//加载属性文件中的键值对数据到属性对象 properties 中去
properties.load(new FileReader("E:\\idea_java_project\\io_project\\src\\Properties.properties"));

//System.out.println(properties);

//String rs = (String) properties.get("smith");
String rs = properties.getProperty("smith");
System.out.println(rs);
=======================
properties的作用?
可以存储Properties属性集的键值对数据到属性文件中去
void store(Writer writer , String comments)
可以加载属性文件中的数据到Properties对象中来
void load(Reader reader)

posted on 2022-03-29 21:49  我要当程序源  阅读(17)  评论(0编辑  收藏  举报

导航