Java uses the specified internationalized file

Source: Internet
Author: User

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

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.