属性文件加载和写入不起作用

时间:2011-07-06 08:23:46

标签: file-io spring-mvc

大家好我在编写属性文件时遇到问题。可以毫无问题地加载属性文件,并且可以更改键值,但在我将其与文件输出流存储后,它似乎完成了它的工作,但属性文件没有变化。

Resource resource = new ClassPathResource("application.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
props.setProperty("image.path", "empty");
OutputStream propOut = new FileOutputStream(new File("application.properties"));
props.store(propOut, "User change");
propOut.close();

我在Spring项目中尝试它。文件application.properties无法更改且没有错误,因此我可以对此问题有任何线索。

您认为我错过了什么?任何帮助都感激不尽。干杯

1 个答案:

答案 0 :(得分:0)

您必须按如下方式存储属性:

props.store(resource.getOutputStream(), "comments");
相关问题