文件目录:

    com.blue.msg.expMessage.properties
    com.blue.msg.expMessage_zh_CN.properties
    com.blue.msg.expMessage_en_US.properties

代码清单:

1 try {
2             String baseName = "com.blue.msg.expMessage";
3             Locale locale = new Locale("aa","bb");
4             ResourceBundle rb = ResourceBundle.getBundle(baseName, locale);
5             String message = rb.getString("db.notfinddriver.error");
6             System.out.println("|:" + message + "|");
7         } catch (Exception e) {
8             e.printStackTrace();
9         }

1. Locale对应的语言版本的properties文件如果不存在的话,先根据系统的语言版本来找对应的properties文件,如果找不到则使用默认的properties文件,比如:
    系统的语言版本是:中文(中国),那么以上的代码肯定是找不到properties文件的,所以会去找expMessage_zh_CN.properties文件,如果这个文件不存在,才会去找expMessage.properties文件。

2. 如果对应的key无法在资源文件中找到,会抛出java.util.MissingResourceException异常。

相关文章:

  • 2021-06-30
  • 2022-01-08
  • 2021-10-12
  • 2021-08-12
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-13
  • 2022-12-23
  • 2021-12-20
  • 2021-06-17
  • 2022-01-06
  • 2021-09-05
  • 2022-12-23
相关资源
相似解决方案