【发布时间】:2011-11-04 09:21:49
【问题描述】:
我正在使用 classLoader 方法来加载属性文件。使用它,我可以检索属性的值,但现在我想更新某些属性的值,但我无法做到。请帮忙。这是代码:
InputStream inputStream = this.getClass().getClassLoader() .getResourceAsStream("PublishDate.properties");
try {
Properties properties = new Properties();
try {
// load the inputStream using the Properties
properties.load(inputStream);
}
catch(Exception e) {
e.printStackTrace();
}
// get the value of the property
String propValue = properties.getProperty("lastHtlProcessPublishDate");
在这里,在 propValue 中,我从文件中获取正确的值。我是这样更新的:
properties.put("lastHtlProcessPublishDate",dateFormatter.format(new Date()));
properties.store(new FileOutputStream("PublishDate.properties"), null);
使用这个值不会得到更新,但是当我提供PublishDate.properties 的完整路径时,它就可以工作了。
但是,我不想给出完整的路径,因为路径是动态的。有人知道如何使用一些相对路径来做到这一点。请给我建议。
【问题讨论】:
标签: java properties