package cn.itcast;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
/*
* Properties与IO相关的方法:
* public void list(PrintStream out) 将属性列表输出到指定的输出流。通常用于调试。
* public void save(OutputStream out, String comments) 将属性列表输出到指定的输出流。已过时。
* public void store(OutputStream out, String comments) throws IOException 将属性列表输出到指定的输出流。
*
* public void load(InputStream inStream)throws IOException 从输入流中读取属性列表(键和元素对)。
*/
public class Demo8 {
public static void main(String[] args) throws IOException {
Properties p = new Properties();
p.setProperty("是否隐身", "在线");
p.setProperty("在线状态", "忙碌");
p.setProperty("是否记住密码", "否");
// PrintWriter pw = new PrintWriter("e.txt");
// p.list(pw);
// pw.close();
// FileOutputStream fos = new FileOutputStream("e.txt");
// p.store(fos, "hello");
// fos.close();
// FileWriter fw = new FileWriter("e.properties");
// p.store(fw, "hello");
// fw.close();
Properties p2 = new Properties();
FileReader fr = new FileReader("e.properties");
p2.load(fr);
fr.close();
System.out.println(p);
}
}
|
|