我有下面的spring类,它尝试在属性文件中写入新的属性值:
@Service
public class Operations {
public void changeProperties() {
Properties prop = new Properties();
OutputStream output = null;
try {
output = new FileOutputStream("rest-endpoint.properties");
prop.setProperty("meta.db.device.url", "localhost");
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
我也尝试了以下代码:
try {
Properties props = new Properties();
props.setProperty("Prop1", "toto");
File f = new File("rest-endpoint.properties");
OutputStream out = new FileOutputStream( f );
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(props, out, "Header Comment");
} catch (Exception e ) {
e.printStackTrace();
}
我的rest-endpoint.properties
文件是:
meta.db.device.url=http://edgex-core-metadata:48081/api/v1/device
meta.db.devicemanager.url=http://edgex-core-metadata:48081/api/v1/devicemanager
meta.db.ping.url=http://edgex-core-metadata:48081/api/v1/ping
但是,当我执行代码时,属性文件中没有任何变化。任何想法可能出什么问题吗?