Read configuration file in Java ResourceBundle and properties two ways to compare

Source: Internet
Author: User
Tags api manual locale

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

Related Article

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.