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/



  • 相关阅读:
    [cf582E]Boolean Function
    [atAGC029F]Construction of a tree
    [atAGC020E]Encoding Subsets
    [gym102769L]Lost Temple
    [atAGC034E]Complete Compress
    [cf566E]Restoring Map
    [atAGC023F]01 on Tree
    [gym102822I]Invaluable Assets
    [gym102900H]Rice Arrangement
    [Offer收割]编程练习赛32
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/6746232.html
Copyright © 2011-2022 走看看