Suppose we want to read a configuration file named Resource.properties, where only the following is true:
Test=hello
Currently I know that there are two ways to read the properties configuration file:
1. Use the Java.util.Properties class to read the code as follows:
New FileInputStream (new File ("XXX"new= properties.getproperty ("test");
2. Read with Java.util,resourcebundle, with the corresponding code (assuming resources.properties under the Classpath):
ResourceBundle bundle = Resourcebundle.getbundle ("resource");//do not include a suffix here. propertiesbundle.getstring ("test ");
Using Method 1 o'clock, when we modify the configuration file execution code, will read out the latest content;
And when we use Method 2 o'clock, after modifying the configuration file, the execution code reads the value does not change, because ResourceBundle will have the cache, when we read the content that reads in the cache.
Currently, if you want to use Method 2 and need to be updated immediately after modifying the configuration file, you can use the Resourcebundle.clearcache () method to clear the cache and reread the contents of the most recent file.
Java Read Properties configuration file