使用properties自带的保存方法,会自动进行转义: 如:url=http://www.baidu.com 保存后变为: url=http://www.baidu.com
Properties prop = new Properties();
File propertiesFile = new File(filePath);
try {
InputStream fis = new FileInputStream(filePath);
prop.load(fis);
OutputStream fos = new FileOutputStream(filePath);
prop.setProperty(parameterName, parameterValue);
prop.store(fos, "Update '" + parameterName + "' value");
}catch (IOException e) {
System.err.println("Visit " + filePath + " for updating " + parameterName + " value error");
}
将自带的store改为直接保存,不转义:
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, "utf-8"));
bw.newLine();
for(Enumeration<?> e = prop.keys(); e.hasMoreElements();) {
String key = (String)e.nextElement();
String val = prop.getProperty(key);
bw.write(key + "=" + val);
bw.newLine();
}
bw.flush();