zoukankan      html  css  js  c++  java
  • 读取properties属性文件——国际化

    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/



  • 相关阅读:
    centos安装rabbitMQ
    迁移文件时发现SyntaxError: Generator expression must be parenthesized
    2020.9.14、星期一
    自己的github 项目怎么构建
    卡尔曼滤波
    模型转换
    vs2019 安装ncnn
    VS2019配置opencv 4.4
    others
    小脚本
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/6746232.html
Copyright © 2011-2022 走看看