1. 以中英两种语言做示例,显示 "hello"
2. 建立英文语言文件 “mess_en_US.properties ”, 输入内容 “hello=welcome you !”, 文件名格式为Java支持的 XX_国家_语言.properties
3. 建立中文语言文件 “mess_zh_CN.properties”,输入内容 “hello=你好”
4. 使用工具 native2ascii 转为Unicode存储, 该工具在 JAVA_HOME目录 bin下
native2ascii mess_zh_CN.properties mess1_zh_CN.properties
native2ascii mess_en_US.properties mess1_en_US.properties
6. 代码示例:
public class Main {
public static void main(String[] args) throws IOException {
Locale [] localeList = Locale.getAvailableLocales();
for( int i=0; i!=localeList.length; i++ )
{ //输出支持的国家和语言
System.out.println( localeList[i].getDisplayCountry() + "=" + localeList[i].getCountry()
+ " " + localeList[i].getDisplayLanguage() + "=" + localeList[i].getLanguage() );
}
Locale mylocale = Locale.getDefault();
ResourceBundle bundle = ResourceBundle.getBundle("mess1", mylocale); //根据系统信息 获取语言包
System.out.println(bundle.getString("hello")); //根据系统 输出对应的值, key -- value
}
}