用法

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

java.util.Properties 读取配置文件中的参数的更多相关文章

  1. 使用 java.util.Properties 读取配置文件中的参数

    配置文件格式 如下的配置参数格式都支持: Key = ValueKey = Key:ValueKey :Value 用法 getProperty方法的返回值是String类型. //读取配置文件 Fi ...

  2. Java.util.properties读取配置文件分析

    Java.util.properties API链接: https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html Clas ...

  3. 关于java.util.Properties读取中文乱码的正确解决方案(不要再用native2ascii.exe了)

    从Spring框架流行后,几乎根本不用自己写解析配置文件的代码了,但近日一个基础项目(实在是太基础,不能用硕大繁琐的Spring), 碰到了用java.util.Properties读取中文内容(UT ...

  4. java使用java.util.Properties读取properties文件的九种方法

    直接上代码: package com.test.test; import java.io.BufferedInputStream; import java.io.FileInputStream; im ...

  5. springboot如何读取配置文件中的参数(例如:application-consts.properties) 又结合maven读取配置文件的顺序

    1.启动项目后,会读取pom.xml中的配置文件,例如现在读取的是本地配置 2.找到对应的配置文件  会读取uri地址下的配置.注:如果为springboot启动无需加config项目的名称,应该本身 ...

  6. ResourceBundle和properties 读取配置文件区别

    java.util.ResourceBundle 和java.util.properties 读取配置文件区别 这两个类都是读取properties格式的文件的,而Properties同时还能用来写文 ...

  7. Java关于Properties用法(二)——替换配置文件中的参数

    上一章讲了配置文件的基本用法,虽然上一章已经可以解决一些需求,但还不些不足之处.假如,配置文件里面的字符串有一部分需要经常变动,另外一些不需要,上一章的方法就不方便了,所以这章主要讲如何在配置文件中使 ...

  8. Android中使用java.util.Properties犯的错

    今天尝试使用java.util.Properties来保存应用配置,然而遇到了好几个问题,对于熟悉此内容的来说可能都是猪一样的错误,但难免有像我一样的新手再次遇到,希望此文能有所帮助. 错误1 jav ...

  9. Java工程中如何读取配置文件中参数信息

    Java中读取配置文件中参数: 方法一:通过JDK中Properties来实现对配置文件的读取. Properties主要用于读取Java的配置文件,不同的编程语言有自己所支持的配置文件,配置文件中很 ...

随机推荐

  1. 47 容器(六)——HashMap

    HashMap的概念 HashMap底层实现了哈希表,这是一种非常重要的数据结构,对于以后我们理解很多技术都有帮助,例如 redis数据库的核心技术和HashMap一样,因此,非常有必要让大家理解. ...

  2. 笨办法学python 习题14 优化过 遇到问题的请看

    print "\t what's you name?"user_name = raw_input('>') from sys import argvscript, = arg ...

  3. application.yml报错:a global security auto-configuration is now provided

    报错原因: Spring Boot 1.5升级到2.0改动 security开头的配置及management.security均已过期 Actuator 配置属性变化 Endpoint变化 参考来源: ...

  4. Linux 系统中如何进入退出 vim 编辑器

    在 Linux 中,vim 编辑器是系统自带的文本编辑器,但要修改某个文本文件,可不是像 Windows 那样操作,更有新手,进入 vi 编辑器后,无法退出以致于强制关机,其实,这个vim(vi)也是 ...

  5. MonoSymbolFileException in CheckLineNumberTable

    Mono.CompilerServices.SymbolWriter.MonoSymbolFileException: Exception of type 'Mono.CompilerServices ...

  6. 在safari下input的placeholder设置行高失效

    在项目中遇到input的placeholder在safari下设置行高失效的问题,亲测 input{ width:250px; height:30px; line-height:30px; font- ...

  7. [破解版]Unity3d引擎最新稳定版本4.5.5下载(官方最新稳定版本)

    来源:http://www.unitymanual.com/thread-28912-1-1.html unity4.5.5 Mac版下载地址:http://pan.baidu.com/s/1hqzi ...

  8. 将集群WEB节点静态数据迁移到共享存储器(LNMP环境)

    系统版本:Centos 6.5 机器及IP规划如下: 192.168.0.117  MySQL 192.168.0.118  nginx+php 192.168.0.123  nfs ①在NFS机器上 ...

  9. elk使用不足及弥补报警措施

    全部都是6.6.2版本,就这还是没有敢选太新的 场景:每个收集点部署filebeat收集响应日志,然后发送到logstash,logstash发送到elasticsearch,和file,这里插一句, ...

  10. c# System.Array