读取properties配置文件代码

public class ConfigUtils {


private static final Logger log = Logger.getLogger(ConfigUtils.class);


private static final String DEPLOY_CONFIG_PROPERTIES = "deploy-config.properties";


private static final String OPERATION_CONFIG_PROPERTIES = "operation-config.properties";


private static final Map<String, String> map = new HashMap<String, String>();


static {
InputStream deployIn = ConfigUtils.class.getClassLoader().getResourceAsStream(ConfigUtils.DEPLOY_CONFIG_PROPERTIES);
InputStream operationIn = ConfigUtils.class.getClassLoader().getResourceAsStream(ConfigUtils.OPERATION_CONFIG_PROPERTIES);
Properties properties = new Properties();
try {
properties.load(deployIn);
properties.load(operationIn);
Set<Entry<Object, Object>> entrys = properties.entrySet();
for (Entry<Object, Object> entry : entrys) {
map.put(entry.getKey().toString(), entry.getValue().toString());
}
} catch (IOException e) {
log.error("load upload.properties wrong");
log.error(e.toString());
} finally {
try {
deployIn.close();
operationIn.close();
} catch (IOException e) {
log.error(e.toString());
}
}
}


/**
* 依据key获取对应的value
* @param key
* @return
*/
public static String getValue(String key) {
String value = null;
String keyValue = map.get(key);
if (StringUtils.isNotBlank(keyValue)) {
value = keyValue.trim();
}
return value;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值