Locale locale = Locale.getDefault();
InputStream in = null;
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
if(locale.getLanguage().equals("zh")) //更加Locale获取对应的资源文件
in = classLoader.getResourceAsStream("log_zh.txt"); //中文资源文件
else
in = classLoader.getResourceAsStream("log_en.txt");//英文资源文件
Properties pro = new Properties();
pro.load(in);
System.out.println(pro.getProperty("3333")); //输出,
System.out.println("/u5fc5/u987b/u662ffloat/u7c7b/u578b");//输出的是中文
博客代码展示了根据系统默认Locale获取对应语言的资源文件。通过Thread.currentThread().getContextClassLoader()获取ClassLoader,根据Locale语言加载中文或英文资源文件,使用Properties类加载文件内容并输出指定属性值。
126

被折叠的 条评论
为什么被折叠?



