`

Java 读取属性文件

 
阅读更多

文件cfg_message.properties

 

public class ProMsgUtil {
	
	private static Log log = LogFactory.getLog(ProMsgUtil.class);
    private static PropertyResourceBundle prb = (PropertyResourceBundle)ResourceBundle.getBundle("cfg_message", new Locale("zh","CN"));

    private ProMsgUtil() {

    }

    public static final String getString(String propertyName) {
    	String message = null;
        try {
        	message = prb.getString(propertyName);   
        }
        catch (Exception e) {
        	log.warn(("没有找到编码[" + propertyName + "]对应的说明信息!"));
        }
        if (StringUtils.isEmpty(message)) {
            return propertyName;
        }
        return message;
    }
    
    public static void main(String[] args) {
    	System.out.println(ProMsgUtil.getString("test"));
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics