i am using the classLoader method to load a property file. Using this, I am able to retrieve the values of properties but now I want to update the values of some properties and i am not able to do it. Please help. Here, is the code:
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");
here, in propValue i get the right value from file. I am updating this like this:
properties.put("lastHtlProcessPublishDate",dateFormatter.format(new Date()));
properties.store(new FileOutputStream("PublishDate.properties"), null);
Using this the value doesn’t get update but when i provide the complete path for PublishDate.properties then it works.
But, I don’t want to give the complete path as the path is dynamic. Does someone knows how to do this using some relative path. Please advise me on this.
You might want to try commons-configuration and use a PropertiesConfiguration. That should satisfy all your needs.