hello world —> 你好 世界
ResourceBundle、Locale类
import java.util.Locale;
import java.util.ResourceBundle;
public class NewHelloWorld {
public static void main(String[] args) {
// 取得系统默认的国家/语言环境
Locale myLocale = Locale.getDefault();
System.out.println(myLocale); //zh_CN
// 根据指定语言_国家环境加载资源文件
ResourceBundle bundle = ResourceBundle.getBundle("message", myLocale);
// 从资源文件中取得的消息
System.out.println(bundle.getString("hello")); //你好, 世界
myLocale = new Locale("en", "US"); //语言 国家, 强制换成en_US
bundle = ResourceBundle.getBundle("message", myLocale);
System.out.println(bundle.getString("hello")); //Hello World
}
}
K(ey)-V(alue)对
message_en_US.properties hello=Hello World
message_zh_CN.properties hello=\u4f60\u597d, \u4e16\u754c
message_zh.properties hello=\u4f60\u597d, \u4e16\u754c
message.properties(如果找不到相对应的语言包的话,会直接选用默认的语言包即后面无加识别内容)
https://blog.csdn.net/flm_0722/article/details/5159988