举例:
config.properties内容如下:Server=127.0.0.1
name=test要把config.properties文件放在classpath里。PropertyResourceBundle configBundle = (PropertyResourceBundle)PropertyResourceBundle.getBundle("config"); //这样调用config.properties文件
server_ip = configBundle.getString("Server"); //得到其中的一个设置

解决方案 »

  1.   

    ResourceBundle最大的好处是可以使你的程序国际化,在bundle文件名后加上国家、语言关键字,那系统就会自动载入相应的bundle文件。
    比如:
        bundle.properties      缺省
        bundle_zh.properties   中文
        bundle_ja.properties   日文ResourceBundle bundle= ResourceBundle.getBundle("bundle");
    如果你的系统是中文的,那就会自动加载bundle_zh.properties   不过多字节编码的bundle需要用native2ascii转成unicode编码。