package com.ck.utils;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
/**
* 读取配置文件的工具类
* @author 52363
*
*/
public class ReadConfigurationFileUtils2 {
/**
* 通过Properties类读取配置文件信息
* @param filePath 配置文件的路径,配置文件可以是properties文件,也可以是cfg文件
* 配置文件中可以是:key=value或者key:value的形式
* @throws Exception
*/
public static void readConfigurationByProperties(String filePath) throws Exception{
Properties properties = new Properties();
//可以用两种不同的流来加载配置文件
//properties.load(new BufferedReader(new FileReader(filePath)));
properties.load(ReadConfigurationFileUtils2.class.getResourceAsStream(filePath));
//也可以指定键名来获取值
//String name = properties.getProperty("name");
Set<Entry<Object,Object>> entrySet = properties.entrySet();
if (entrySet.size() > 0) {
for (Entry<Object, Object> entry : entrySet) {
System.out.println(entry.getKey()+" -- "+entry.getValue());
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
使用Properties类来读取配置文件
共17个文件
properties:4个
class:4个
java:2个
需积分: 50 11 下载量 44 浏览量
2017-10-27
20:36:14
上传
评论
收藏 227KB ZIP 举报
温馨提示
使用Java中的Properties类的方法,以及类加载器来读取配置文件中的信息。可以读取.properties文件和.cfg文件。详细代码+注释+测试例子
资源推荐
资源详情
资源评论
收起资源包目录
readConfigurationFile.zip (17个子文件)
readConfigurationFile
.project 397B
src
resource
test2.cfg 31B
test1.properties 37B
com
ck
utils
ReadConfigurationFileUtils2.java 1KB
test
TestReadFile2.java 612B
lib
junit-4.10.jar 247KB
.settings
org.eclipse.jdt.core.prefs 598B
org.eclipse.core.resources.prefs 128B
.classpath 358B
bin
resource
test3_zh_CN.properties 34B
test2.cfg 31B
test3_en_US.properties 25B
test1.properties 37B
com
ck
utils
ReadConfigurationFileUtils2.class 2KB
ReadConfigurationFileUtils.class 3KB
test
TestReadFile.class 1KB
TestReadFile2.class 734B
共 17 条
- 1
资源评论
小狐狸218
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功