ResourceBundle How to read the properties file not in the jar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.