读取properties属性文件——国际化

来源:互联网 发布:足不出户而知天下三分 编辑:程序博客网 时间:2024/04/30 04:26
public class PropertiesInfo {/** * PropertiesInfo实例 */private static PropertiesInfo pi = null;private static ResourceBundle resource;/** * 资源文件基名 * 该资源文件应该放置在classpath下 */private final String PROPERTIES_BASE_NAME = "MessageResources";/** * 构建资源文件对象 * */private PropertiesInfo() {resource = ResourceBundle.getBundle(PROPERTIES_BASE_NAME);}/** *  获取一个PropertiesInfo实例 * @return PropertiesInfo */public static synchronized PropertiesInfo getInstance() {if(pi == null) {pi = new PropertiesInfo();}return pi;}/** * 根据资源文件的key读取值 * @param key * @return String */public String getValue(String key) {return resource.getString(key);}/** * 根据资源文件的key读取值 * @param key * @param args * @return String */public String getValue(String key, Object args[]) {return MessageFormat.format(resource.getString(key), args);}}


对于ResourceBundle的说明http://lavasoft.blog.51cto.com/62575/184605/



0 0