1.定义三个资源文件,放到src的根目录下面

  命名规范是: 自定义名_语言代码_国别代码.properties
  默认 : 自定义名.properties
 
2.资源文件都必须是ISO-8859-1编码,因此,对于所有非西方语系的处理,都必须先将之转换为Java Unicode Escape格式。
转换方法是通过JDK自带的工具native2ascii.exe,直接输入中文后回车,或者如下:
  native2ascii -encoding gbk my.properties my_zh_CN.properties
 
3.读取
public class LoadMyproperties {
    public static void main(String[] args) { 
        Locale locale1 = new Locale("zh", "CN"); 
        ResourceBundle resb1 = ResourceBundle.getBundle("my", locale1); 
        System.out.println(resb1.getString("name")); 

        ResourceBundle resb2 = ResourceBundle.getBundle("my", Locale.getDefault()); 
        System.out.println(resb1.getString("name")); 

        Locale locale3 = new Locale("en", "US"); 
        ResourceBundle resb3 = ResourceBundle.getBundle("my", locale3); 
        System.out.println(resb3.getString("name")); 
    } 
}

 

 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-12-09
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2021-11-21
  • 2022-12-23
  • 2021-12-13
  • 2021-10-04
  • 2021-11-18
  • 2021-06-28
相关资源
相似解决方案