用法

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

最新文章

  1. VelocityTracker
  2. iOS 给UILabel文字加下划线
  3. java基础知识回顾之javaIO类---FileWriter和FileReader
  4. 实用技巧:简单而有用的nohup命令介绍(转)
  5. 细细探究MySQL Group Replicaiton — 配置维护故障处理全集
  6. jsp上的九个隐含对象
  7. OLEDB数据源
  8. 配置Java文件
  9. 一个不错的git资源站点
  10. PAT 1004 成绩排名 (20)(代码)
  11. python版本坑:md5例子(python2与python3中md5区别)
  12. 1. 请问PHP里的ECHO是什么意思 ?请问PHP里的ECHO是什么意思???有什么作用???又应该怎么使用???
  13. 复习_for循环嵌套 及 流程图梳理
  14. MySQL 中间件 mycat 的使用
  15. C的指针疑惑:C和指针13(高级指针话题)
  16. mongodb可视化客户端下载
  17. [ python ] 项目一:FTP程序
  18. [原]Android打包之Ant打包
  19. (原创)白话KMP算法(续)
  20. win7下怎么卸载jdk

热门文章

  1. Django学习之django自带的contentType表
  2. PAT(B) 1085 PAT单位排行(Java:20分)
  3. XGBoost 重要参数(调参使用)
  4. ListModelSerializer模块
  5. Python3基础语法(20190617)
  6. quartz2.3.0(四)JobDataMap—带状态集合的定时器内置集合
  7. 二分法在JavaScript中的应用实例
  8. 支付宝支付回调方法RSA2验签失败处理方法
  9. Java中BIO和NIO
  10. Switch开关在element-ui表格中点击没有效果解决方法