使用properties.store方法将修改后的properties对象写入后,原文件没有变化,但下次读取时,读到的是修改后的值,代码如下:
public static void setValue(String key, String value) throws FileNotFoundException, IOException {
properties.remove(key);
properties.put(key, value);
Resource res = new ClassPathResource(
"/cache/config/property/commonconfig.properties");
FileOutputStream fileOutputStream = new FileOutputStream(res.getFile());
properties.store(fileOutputStream, null);
fileOutputStream.flush();
fileOutputStream.close();
}
重启过电脑了,文件还是没变化,值还是修改后的值