Reading the configuration file-Introduction to resourcebundle

Source: Internet
Author: User
The properties class can be used to read the configuration file information in Java, but it is difficult to solve the internationalization problem. Therefore, it is best to use the resourcebundle class, actually, resourcebundle is essentially a ing with properties, both of which store information in the form of key-value pairs, but it is more flexible. When resourcebundle res = resourcebundle is called. getbundle ("area", locale. china );
String input = res. getstring ("25 ");
System. Out. println (input );

When the program automatically finds the file named area_zh.properties in the class path, and finds out the content with the key value 25, which is saved in iso8859 encoding, but because resourcebundle res = resourcebundle is specified. getbundle ("area", locale. china), so when we call the getstring method, we will get the Chinese format of the key value 25 corresponding to the content

A lot of string information is required in the program. If you write it directly in the program, you must re-compile the string to change it. Using resourcebundle can avoid this problem. properties file. This property file can be changed at any time. Example: 1. messages. properties onlyfun. caterpillar. welcome = Hello onlyfun. caterpillar. name = World 2. testresourcebundle. java import Java. util. resourcebundle; public class testresourcebundle {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub resourcebundle Resource = resourcebundle. getbundle ("messages"); system. Out. Print (resource. getstring ("onlyfun. Caterpillar. Welcome") + "! "); System. Out. println (resource. getstring (" onlyfun. Caterpillar. Name ") + "! ");}}


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.