java.util.Properties 读取配置文件中的参数
2024-09-22 21:49:21
用法
getProperty方法的返回值是String类型。
java.util.Properties 读取配置文件中的参数 //读取配置文件
FileInputStream inStream = null;
try {
inStream = new FileInputStream("/fetchedfile/redis.conf");
Properties prop = new Properties();
prop.load(inStream);
Field field;
String property;
//将配置参数读到对象中
for(Map.Entry<String, String> entry : RedisConstants.REDIS_PARAM.entrySet()){
System.out.println(entry.getKey() + ": " + prop.getProperty(entry.getKey()));
field = redisServiceParam.getClass().getDeclaredField(entry.getValue());
field.setAccessible(true);
//获取参数
property = prop.getProperty(entry.getKey());
if(null == property || property.isEmpty()){
field.set(redisServiceParam, null);
}else{
field.set(redisServiceParam, property);
}
}
} catch (IOException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}finally {
if (inStream != null) {
try {
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
最新文章
- VelocityTracker
- iOS 给UILabel文字加下划线
- java基础知识回顾之javaIO类---FileWriter和FileReader
- 实用技巧:简单而有用的nohup命令介绍(转)
- 细细探究MySQL Group Replicaiton — 配置维护故障处理全集
- jsp上的九个隐含对象
- OLEDB数据源
- 配置Java文件
- 一个不错的git资源站点
- PAT 1004 成绩排名 (20)(代码)
- python版本坑:md5例子(python2与python3中md5区别)
- 1.	请问PHP里的ECHO是什么意思 ?请问PHP里的ECHO是什么意思???有什么作用???又应该怎么使用???
- 复习_for循环嵌套 及 流程图梳理
- MySQL 中间件 mycat 的使用
- C的指针疑惑:C和指针13(高级指针话题)
- mongodb可视化客户端下载
- [ python ] 项目一:FTP程序
- [原]Android打包之Ant打包
- (原创)白话KMP算法(续)
- win7下怎么卸载jdk