读取资源包配置文件工具类

    1.统一约定在项目的类路径下 /configures/kernel.properties     

    2.配置各类型配置输入

   

/**
 * 初始化属性表
 */
package com.test.xml;

import java.util.ResourceBundle;

import org.apache.commons.lang.StringUtils;

/**
 * @author Administrator
 *
 */
public class ReadProperties {
	public static ResourceBundle bundle;
	static {
		try {
			bundle = ResourceBundle.getBundle("resource/kernel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param key
	 *            配置键
	 * @param defValue
	 *            默认值
	 * @return 如果配置不存在或为空字符串,则返回默认字符串
	 */
	public static String getPropDefIfBlank(String key, String defValue) {
		if (ReadProperties.bundle.containsKey(key)) {
			String ret = ReadProperties.bundle.getString(key);
			if (StringUtils.isNotBlank(ret)) {
				return ret;
			}
		}
		return defValue;
	}
}

猜你喜欢

转载自wo-niu.iteye.com/blog/2275695