mev*_*esh 12 java spring properties-file
我有一些要求,我想在我使用my spring应用程序的属性文件中编写/更新值.
我用谷歌搜索了它,但我还没有找到使用Spring的直接方法.
有没有人知道如何做或有任何最好的方法来做到这一点.
提前致谢.
Deh*_*Deh 16
你可以这样做:
public void saveParamChanges() {
try {
// create and set properties into properties object
Properties props = new Properties();
props.setProperty("Prop1", "toto");
props.setProperty("Prop2", "test");
props.setProperty("Prop3", "tata");
// get or create the file
File f = new File("app-properties.properties");
OutputStream out = new FileOutputStream( f );
// write into it
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(props, out, "Header COmment");
} catch (Exception e ) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:使用org.springframework.Util中的defaultPropertiesPersiter进行更新
| 归档时间: |
|
| 查看次数: |
11982 次 |
| 最近记录: |