將Properties文件的鍵值對調換位置重新生成一個文件 – JAVA編程語言程序開發技術文章

Properties props = new Properties();

InputStream in = new BufferedInputStream(new FileInputStream(GenPath
.getAddress()
+ "\\city.properties"));
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
props.load(bf);
Set<Object> list = props.keySet();
File f = new File(GenPath.getAddress() + "\\city_1.properties");
FileOutputStream fos = new FileOutputStream(f);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos,
"UTF-8"));
for (Object o : list) {
System.out.println(props.getProperty(o.toString()));
writer.write(props.getProperty((String) o) + "=" + o.toString()
+ "\r\n");
}
writer.flush();
writer.close();
System.out.print("over");

 

摘自  園林鳥 

發佈留言