public static void main(String[] args) throws IOException {
test();
}
private static void test() throws IOException {
File file = new File("c:\\info.txt");
if(file.exists()){
file.createNewFile();
}
FileReader fr = new FileReader(file);
FileWriter fw = new FileWriter(file);//为什么语句放在这里后,文件内部的内容只有"zhangsan","10",之前写入的信息全部都没有了
Properties prop = new Properties();
prop.load(fr);
prop.setProperty("zhangsan", "10");
prop.list(System.out);
prop.store(fw, "");
fr.close();
fw.close();
}
private static void propertiesDemo_1() throws IOException {
Properties prop = new Properties();
prop.setProperty("zhangsan","21");
prop.setProperty("lisi","22");
prop.setProperty("wangwu","23");
prop.setProperty("zhaoliu","24");
Set<String> names = prop.stringPropertyNames();
FileOutputStream fos = new FileOutputStream("c:\\info.txt");
prop.store(fos, "name+age");
fos.close();
}
|