用 类名.class.getClassLoader().getResourceAsStream来获得config目录下的properties配置文件


public final class ConfigUtil {

private static Logger log = LoggerFactory.getLogger(ConfigUtil.class);

/**
* 属性对象
*/
private static Properties props;

/** 私有的构造函数 */
public ConfigUtil() {

props = null;
}

/**
* 根据属性key得到对应的属性值
*
* @param key
* 键名称
* @return
*/
public static String getPropsValueByKey(String filePath, String key) {
// if (props == null) {
props = new Properties();
InputStream resourceStream = ConfigUtil.class.getClassLoader().getResourceAsStream(filePath);
try {
props.load(resourceStream);
} catch (IOException e) {
String error = "配置文件工具类-根据属性key得到对应的属性值方法出现异常!";
log.error(error, e);
}
// }
return props.getProperty(key);
}
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM