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