Today in the development, need to put some information into the configuration file, easy to follow the changes, note that the use of ResourceBundle read configuration file, remember before also saw the use of properties, it is more curious about the difference between the two ways, Check the web and check the Java API Manual, a brief summary of the record:
A major difference between ResourceBundle and properties is that ResourceBundle supports language internationalization, and when a program needs a locale-specific object, it uses the getBundle
method to load the ResourceBundle
class:
New Locale ("zh", "CN"); = Resourcebundle.getbundle ("Resources", Locale). getString ("key");
Use the above method to read the key value pairs of the k-v, and the properties inherit the Hashtable, the way is loaded by the stream, as follows:
New Properties (); Prop.load (MyClass. class . getClassLoader (). getResourceAsStream ( "resources.properties"= (String) prop.getproperty (" Key ");
The normal requirements above two ways to achieve both can be used when the attention of catch exception.
Read configuration file in Java ResourceBundle and properties two ways to compare