https://www.programmersought.com/article/44943226090/
ResourceBundle file is read in the classpath, that is, the src or src directory, and we need to be packaged in the project, properties files packed in jar, modify inconvenient, we need to be placed outside the jar file properties you can be modified at any time.
1, generally the default mode ResourceBundel read file is read path CLASSPATH, configuration file named resourceBundle.properties. In the src root directory:
ResourceBundle rb=ResourceBundle.getBundle("resourceBundle")
2, resourceBundle.properties placed in a folder, such as the new config folder,
private static ResourceBundle rb; private static BufferedInputStream inputStream; static { String proFilePath = System.getProperty("user.dir") +"\\config\\resourceBundle.properties"; try { inputStream = new BufferedInputStream(new FileInputStream(proFilePath)); rb = new PropertyResourceBundle(inputStream); inputStream.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
No comments:
Post a Comment