Any one please help me on reloading properties file.
i have the 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.
Am not able to get the latest modifications in the same program execution.
Can any one 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.