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"));
    }
}

 

你可能感兴趣的:(java)