Properties的方法:
void list(PrintWriter out)
void load(Reader reader)
void store(Writer writer,String Comments)
list()与store()的区别
list只能接收打印流
store可接受任意输出流(字节、字符等)
public class PropertiesDemo2 {
public static void main(String[] args) throws IOException {
//void list(PrintWriter out)
// method1();
//method2();
//创建属性列表对象
Properties prop=new Properties();
//添加映射关系
prop.setProperty("理工111", "李倩倩");
prop.setProperty("理工112", "李建民");
prop.setProperty("理工113", "李朱泥");
//创建输出流对象
//void store(Writer writer,String Comments)
Writer w=new FileWriter("bb.txt");
prop.store(w, "PropertiesTest");
//释放资源
w.close();
}
private static void method2() throws FileNotFoundException, IOException {
//创建属性列表对象
Properties pro=new Properties();
//创建输入流对象
//void load(Reader reader)
FileReader fr=new FileReader("cc.txt");
pro.load(fr);
//释放资源
fr.close();
System.out.println(pro);
}
private static void method1() throws FileNotFoundException {
Properties prop=new Properties();
//添加映射关系
prop.setProperty("理工111", "李倩倩");
prop.setProperty("理工112", "李建民");
prop.setProperty("理工113", "李朱泥");
//创建打印流对象
PrintWriter out=new PrintWriter("cc.txt");
prop.list(out);
//释放资源
out.close();
}
}
网友评论