读取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/



原文地址:https://www.cnblogs.com/claireyuancy/p/6746232.html