Java code:
ImportJava.util.Locale;Importorg.junit.Test;/*** Use the specified internationalized file*/ Public classDemo {@Test Public voidTestName1 ()throwsException {//specify internationalization for Chinese ChineseLocale locale =NewLocale ("zh", "CN"); /** Getbundle first parameter (baseName): * |-The default path is the Classpath path. * |-If the reference ' Myres ', will go to SRC under the Myres to start the properties file; such as: src/myres (*). Properties * | If the reference ' Demos/java/util/locale/myres ', then go to SRC under the path of ' Demos/java/util/locale ' folder Myres (*). properties file. * * Getbundle's second parameter (locale): * |-Specifies which international language to use. * |-If you specify the use of the Internationalized language new locale ("zh", "CN"), then go to myres_zh_cn.properties file * |-If you specify the use of the internationalized language new Locale ("en", "US"); then go to myres_en_us.properties file * | If the above two files cannot be found, go to the Myres.properties file (default). */Java.util.ResourceBundle ResourceBundle= Java.util.ResourceBundle.getBundle ("Demos/java/util/locale/myres", Locale); System.out.println (Resourcebundle.getstring ("AAA")); System.out.println (Resourcebundle.getstring ("BBB")); /** Print Results *----------* Very good * Thank you*/} @Test Public voidTestName2 ()throwsException {locale locale=NewLocale ("en", "US"); Java.util.ResourceBundle ResourceBundle= Java.util.ResourceBundle.getBundle ("Demos/java/util/locale/myres", Locale); System.out.println (Resourcebundle.getstring ("AAA")); System.out.println (Resourcebundle.getstring ("BBB")); /** Print Results *-------------* Good * Thanks*/ }}
Internationalized file Path (Src/demos/java/util/locale):
Myres.properties
Aaa=good Bbb=thanks
Myres_en_us.properties
Aaa=good Bbb=thanks
Myres_zh_cn.properties
aaa=\u5f88\u597d BBB=\U8C22\U8C22
Java uses the specified internationalized file