Anyone please help me on reloading properties file. I have code like this
Properties prop = new Properties();
InputStream trackerFileStream =
LoadProperty.class.getClassLoader().getResourceAsStream("sample.properties");
prop.load(trackerFileStream);
After loading the properties file through class loader, I modify the properties file. I am not able to get the latest modifications in the same program execution.
Can anyone please suggest me how to reload the properties file without re-executing the program?
If you want to be updated you need to check the resource from tome to time and reload the properties.
It is a problem that you are loading properties from classpath. If you use file system you can check the last modified attribute of file and decide whether to reload it. In java 7 you evern can register listener that will call you back when file is modified. You can't do this when loading resource.
But you can do better. Use configuration package from apache. It already implements reloading logic, so you just can work against "configuration" actually mapped to resource and be sure you always get updated data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With