ResourceBundle read the file is under the Classpath path, that is, src or src directory, and we need to package in the project, packaged properties file in the jar, modification is very inconvenient, We need to place the properties file outside the jar to be modified at any time.
1, in general, Resourcebundel read the file by default, the read path is classpath, the configuration file name is resourcebundle.properties. Under the SRC root directory is:
ResourceBundle rb=resourcebundle.getbundle ("ResourceBundle")
If under a package, it is: Package.resourcebundle, for example, under the XCC package:
ResourceBundle rb=resourcebundle.getbundle ("Xcc.resourcebundle")
2, Resourcebundle.properties placed in a folder, such as the new Config folder,
private static ResourceBundle rb;private static Bufferedinputstream inputstream;static {//RB = Resourcebundle.getbundle ("Xcc.resourcebundle"); String ProfilePath = System.getproperty ("User.dir") + "\\config\\resourceBundle.properties"; try {inputstream = new Bufferedinputstream (New FileInputStream (ProfilePath)); RB = new propertyResourceBundle (InputStream);} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated catch Blocke.printstacktrace ();}}
3, if you need to configure in the spring configuration file, you can refer to the following configuration:
<context:property-placeholder location= "File:./properties/jdbc.properties"/>
You can modify the properties file directly after packing.
ResourceBundle How to read the properties file not in the jar