配置文件格式

如下的配置参数格式都支持:

Key = Value
Key =
Key:Value
Key  :Value

用法

getProperty方法的返回值是String类型。

        //读取配置文件
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 读取配置文件中的参数

    用法 getProperty方法的返回值是String类型. java.util.Properties 读取配置文件中的参数 //读取配置文件 FileInputStream inStream = n ...

  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. Android中使用java.util.Properties犯的错

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

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

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

  9. 使用java.util.Properties类读写配置文件

    J2SE 1.5 以前的版本要求直接使用 XML 解析器来装载配置文件并存储设置,虽说也并非难事,相比 java.util.Properties却要做额外的解析工作.而java.util.Proper ...

随机推荐

  1. VxWorks引导启动过程

    https://blog.csdn.net/phunxm/article/details/6979089

  2. Kendo UI使用教程:CDN服务

    [Kendo UI最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support for React和 ...

  3. 一、redis安装、配置、命令

    一.安装 参见:redis中文官方文档 “http://www.redis.cn/download.html” 下载.解压.编译Redis $ wget http://download.redis.i ...

  4. 通过源码安装PostgresSQL

    通过源码安装PostgresSQL 1.1 下载源码包环境: Centos6.8 64位 yum -y install bison flex readline-devel zlib-devel yum ...

  5. [每日一讲] Python系列:字符串(下)

    字符串的常见操作 """ DATA STRUCTURE Container: Sequence -- String String is immutable.If stri ...

  6. python 关于字节串和字符串

    import pickle s=pickle.dumps(clf) f=open('svm.txt','wb') #使用二进制方式打开,write进字节,否则进字符 f.write(s) f.clos ...

  7. linux 内存

    [转]Linux 查看内存(free buffer cache) 转自:http://elf8848.iteye.com/blog/1995638 Linux下如何查内存信息,如内存总量.已使用量.可 ...

  8. WEB上传大文件

    众所皆知,web上传大文件,一直是一个痛.上传文件大小限制,页面响应时间超时.这些都是web开发所必须直面的. 本文给出的解决方案是:前端实现数据流分片长传,后面接收完毕后合并文件的思路.下面贴出简易 ...

  9. UML——概述

    1. 静态视图(类图)      静态视图不描述与时间相关的系统行为,这种行为在其他视图中描述,因此称之为静态试图.      静态视图用类图来实现,正因为它以类图为中心,因此也称之为类图.     ...

  10. Devexpress MVC DropDownList (持续更新))

    @Html.DevExpress().DropDownEdit(settings => { settings.Name = "psBankCharge"; settings. ...