java.util.Properties 读取配置文件中的参数
用法
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 读取配置文件中的参数的更多相关文章
- 使用 java.util.Properties 读取配置文件中的参数
配置文件格式 如下的配置参数格式都支持: Key = ValueKey = Key:ValueKey :Value 用法 getProperty方法的返回值是String类型. //读取配置文件 Fi ...
- Java.util.properties读取配置文件分析
Java.util.properties API链接: https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html Clas ...
- 关于java.util.Properties读取中文乱码的正确解决方案(不要再用native2ascii.exe了)
从Spring框架流行后,几乎根本不用自己写解析配置文件的代码了,但近日一个基础项目(实在是太基础,不能用硕大繁琐的Spring), 碰到了用java.util.Properties读取中文内容(UT ...
- java使用java.util.Properties读取properties文件的九种方法
直接上代码: package com.test.test; import java.io.BufferedInputStream; import java.io.FileInputStream; im ...
- springboot如何读取配置文件中的参数(例如:application-consts.properties) 又结合maven读取配置文件的顺序
1.启动项目后,会读取pom.xml中的配置文件,例如现在读取的是本地配置 2.找到对应的配置文件 会读取uri地址下的配置.注:如果为springboot启动无需加config项目的名称,应该本身 ...
- ResourceBundle和properties 读取配置文件区别
java.util.ResourceBundle 和java.util.properties 读取配置文件区别 这两个类都是读取properties格式的文件的,而Properties同时还能用来写文 ...
- Java关于Properties用法(二)——替换配置文件中的参数
上一章讲了配置文件的基本用法,虽然上一章已经可以解决一些需求,但还不些不足之处.假如,配置文件里面的字符串有一部分需要经常变动,另外一些不需要,上一章的方法就不方便了,所以这章主要讲如何在配置文件中使 ...
- Android中使用java.util.Properties犯的错
今天尝试使用java.util.Properties来保存应用配置,然而遇到了好几个问题,对于熟悉此内容的来说可能都是猪一样的错误,但难免有像我一样的新手再次遇到,希望此文能有所帮助. 错误1 jav ...
- Java工程中如何读取配置文件中参数信息
Java中读取配置文件中参数: 方法一:通过JDK中Properties来实现对配置文件的读取. Properties主要用于读取Java的配置文件,不同的编程语言有自己所支持的配置文件,配置文件中很 ...
随机推荐
- 【微信小程序学习笔记】入门与了解
[微信小程序学习笔记(一)] IDE 下载安装 下载地址 官方工具:https://mp.weixin.qq.com/debug/w … tml?t=1476434678461 下载可执行文件后,可按 ...
- Quartus II——工程建立和常用设置
Quartus ii是针对Altera FPGA的一款EDA软件,在此以一个led闪烁工程来简单说一下基本操作: 一.注意事项 Quartus ii最大的注意事项就一点:工程名称以及工程里面的文件名称 ...
- Linux设置普通用户无密码sudo权限
配置普通用户无密码sudo权限: root用户进入到Linux系统的/etc目录下 cd /etc 将sudoers文件赋予写的权限 chmod u+w /etc/sudoers 编辑sudoers文 ...
- python MySQL 插入Elasticsearch
一.需求分析 注意: 本环境使用 elasticsearch 7.0版本开发,切勿低于此版本 mysql 表结构 有一张表,记录的数据特别的多,需要将7天前的记录,插入到Elasticsearch中, ...
- spring boot 中@Autowired注解无法自动注入的错误
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/huihuilovei/article/de ...
- 配置Setting.xml文件提高maven更新下载jar包速度
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- IIS配置文件的XML格式不正确 applicationHost.config崩溃
错误提示如图: 检查C:\Windows\System32\inetsrv\config目录下的applicationHost.config文件,备份一份. 可使用IIS提供的AppCmd.exe的r ...
- C#只读属性
using System; using System.Collections.Generic; using System.Text; namespace 面向对象 { class Person { / ...
- System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常。如果您在连接到 SQL Azure 数据库,请考虑使用 SqlAzureExecutionStrategy。
代码异常描述 ************** 异常文本 **************System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常.如果 ...
- JAVA基础之ServletContext应用
创建一个登陆的界面,并且统计次数! 导入jar包; 1. driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/java0603?u ...