Java Read Properties configuration file

Source: Internet
Author: User

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

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.