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 ") + "! ");}}