package com.demo.util;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStreamReader;
import java.util.Properties;
public class PropertiesUtil {
public static Logger logger= LoggerFactory.getLogger(PropertiesUtil.class);
private static Properties properties;
static {
String passwordSalt="utilpro.properties";
properties=new Properties();
try {
properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(passwordSalt),"utf-8"));
}catch (Exception exc){
logger.error("读取配置文件失败",exc);
}
}
public static String getProperty(String key){
String value = properties.getProperty(key.trim());
if(StringUtils.isBlank(value)){
return null;
}
return value.trim();
}
public static String getProperty(String key,String defaultValue){
String value = properties.getProperty(key.trim());
if(StringUtils.isBlank(value)){
value = defaultValue;
}
return value.trim();
}
}
转载于:https://www.cnblogs.com/taigasweet/p/9804410.html