zoukankan      html  css  js  c++  java
  • ResourceBundle类读取properties文件

    1.Properties与ResourceBundle类都可以读取属性文件key/value的键值对

    2.ResourceBundle类主要用来解决国际化和本地化问题,国际化时properties文件命名规范:

      一般的命名规范是: 自定义名语言代码国别代码.properties,如果是默认的,直接写为:自定义名.properties。

      例如:

      res_en_US.properties 
      res_zh_CN.properties                                       res.properties

      系统会自动选择属性资源文件

    3.使用:

      ResourceBundle bundle = ResourceBundle.getBundle("res", new Locale("zh", "CN"));

      new Locale(“zh”, “CN”)提供本地化信息

      程序会首先在classpath下寻找res_zh_CN.properties文件,若res_zh_CN.properties文件不存在,则取找res_zh.properties,如还是不存在,继续寻找res.properties,若都找不到就抛出异常。

    • 获取ResourceBundle实例bundle 后可以通过下面的方法获得本地化值。
    • getObject(String key);
    • getString(String key);
    • getStringArray(String key);

     如:bundle = ResourceBundle.getBundle("res", Locale.US);

      bundle = ResourceBundle.getBundle("res", Locale.getDefault());

      value= bundle.getString("key");

    注意:ResourceBundle.getBundle("xxx", Locale.US);

      ResourceBundle类基于类读取属性文件:将属性文件当作类,意味着属性文件必须放在包中(或src根目录下),使用属性文件的全限定性类名而非路径指代属性文件。

      ResourceBundle bundle = ResourceBundle.getBundle("com.rong.res.application");此时读取的是com.rong.res包下的application.properties属性文件

  • 相关阅读:
    How To Use Google Logging Library (glog)
    段错误调试
    getline 使用
    remove_if筛选数组元素
    getline C++ Reference
    c++ Why remove_copy_if returns an empty vector? Stack Overflow
    About iClick
    哈工大社会计算与信息检索研究中心
    python的16进制和10进制间的转换
    毕业生 哈尔滨工业大学社会计算与信息检索研究中心 理解语言,认知社会
  • 原文地址:https://www.cnblogs.com/57rongjielong/p/8878096.html
Copyright © 2011-2022 走看看