Apache Commons configuration使用入门
使用Commons Configuration可以很好的管理我们的配置文件的读写,
官网:http://commons.apache.org/configuration
需要用到commons-lang,commons-collections,commons-logging,log4j jar包
public class Test {
public static void main(String[] args) throws ConfigurationException, InterruptedException {
xmlLoadTest();
fileLoadTest();
saveTest();
runtimeReload();
}
//xml文件
public static void xmlLoadTest() throws ConfigurationException{
String file = "test1.xml";
XMLConfiguration config = new XMLConfiguration(Test.class.getResource(file));
System.out.println(config.getString("conf.url"));
System.out.println(config.getDouble("conf.money"));
}
//properties文件
private static void fileLoadTest() throws ConfigurationException {
String file = "test2.properties";
PropertiesConfiguration config = new PropertiesConfiguration(Test.class.getResource(file));
System.out.println(config.getString("url"));
}
//保存到文件
public static void saveTest() throws ConfigurationException{
String file = "test2.properties";
PropertiesConfiguration config = new PropertiesConfiguration(Test.class.getResource(file));
//设置自动保存 或显示调用 config.save();
config.setProperty("colors.background", "#000000");
config.setAutoSave(true);
}
//运行期参数修改加载
public static void runtimeReload() throws ConfigurationException, InterruptedException{
String file = "test2.properties";
PropertiesConfiguration config = new PropertiesConfiguration(Test.class.getResource(file));
config.setReloadingStrategy(new FileChangedReloadingStrategy());
System.out.println(config.getString("url"));
Thread.sleep(10000);//在休眠期间,手动修改文件里面的url值后观察日志情况
System.out.println(config.getString("url"));
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Apache Commons configuration使用入门的更多相关文章
- 使用Apache Commons Configuration读取配置信息
在项目中使用一些比较新的库总会给你带来很多快乐,在这篇文章中,我将会给你介绍一个在Java中读取配置文件的框架——Apache Commons Configuration framework. 你会了 ...
- Apache Commons Configuration读取xml配置
近期项目自己手写一个字符串连接池.因为环境不同有开发版本.测试版本.上线版本.每一个版本用到的数据库也是不一样的.所以需要能灵活的切换数据库连接.当然这个用maven就解决了.Apache Commo ...
- Apache Commons Configuration的应用
Apache Commons Configuration的应用 Commons Configuration是一个java应用程序的配置管理工具.可以从properties或者xml文件中加载软件的配置 ...
- Apache Commons IO入门教程(转)
Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...
- [转]Apache Commons IO入门教程
Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...
- commons configuration管理项目的配置文件
Commons Confifutation commons configuration可以很方便的访问配置文件和xml文件中的的内容.Commons Configuration 是为了提供对属性文件. ...
- Apache Commons 常用工具类整理
其实一直都在使用常用工具类,只是从没去整理过,今天空了把一些常用的整理一下吧 怎么使用的一看就明白,另外还有注释,最后的使用pom引入的jar包 public class ApacheCommonsT ...
- Commons Configuration之二基本特性和AbstractConfiguration
Configuration接口定义一大堆方法.一切从头开始实现这些方法非常困难.因为AbstractConfiguration类存在.该类在Commons Configuration中充当大多数Con ...
- apache commons io入门
原文参考 http://www.javacodegeeks.com/2014/10/apache-commons-io-tutorial.html Apache Commons IO 包绝对是 ...
随机推荐
- Android DevArt1:假设当前Activity为A,如果这时用户打开一个新的Activity B,那么B的onResume和A的onPause哪个先执行呢?
问题描述:假设当前Activity为A,如果这时用户打开一个新的Activity B,那么B的onResume和A的onPause哪个先执行呢? GitHub Demo 废话少说,上代码,Activi ...
- Angular2 web project UltraRacing (一,如何启动一个Angular项目?)
要稍等一会 切到目录看看 OK,生成很多文件 那么 我们来启动吧 出现下面信息说明成功 而且每次我们编译文件后 都会在cmd里面显示这个信息 说明他是热部署的 然后我们去浏览器看看 说明一切OK!
- ArcGIS案例学习笔记-CAD数据自动拓扑检查
ArcGIS案例学习笔记-CAD数据自动拓扑检查 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 功能:针对CAD数据,自动进行拓扑检查 优点:类别:地理建模项目实例 ...
- Unity3D架构设计NavMesh寻路
Unity3D架构设计NavMesh寻路 发表于2013年10月6日由陆泽西 国庆闲来没事把NavMesh巩固一下.以Unity3D引擎为例写一个底层c# NavMesh寻路.因为Unity3D中本身 ...
- 吴裕雄 20-MySQL NULL 值处理
MySQL NULL 值处理我们已经知道 MySQL 使用 SQL SELECT 命令及 WHERE 子句来读取数据表中的数据,但是当提供的查询条件字段为 NULL 时,该命令可能就无法正常工作.为了 ...
- Anaconda安装及配合pycharm使用
首先到https://www.anaconda.com/download/下载合适的anaconda版本.如Windows 64bit. 下载了直接双击开始下载,一路同意下去,到选择安装的目录.这里选 ...
- SpringCloud---Feign上传下载详解
1.使用原因 公司最近做的项目在用SpringCloud,涉及到了上传.但是Feign本身是不支持文件类型的.所以这里把上传下载的实现分享一下. 2.所需配置 这是自己实现的一个formEncoder ...
- js性能提高篇
,最后统一将DocumentFragment添加到页面. 该做法可以减少页面渲染dom元素的次数.经IE和Fx下测试,在append1000个元素时,效率能提高10%-30%
- python网络编程之开启进程的方式
标签(空格分隔): 开启进程的方式 multiprocessing模块介绍: python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在pyth ...
- 材料订单不在IN_MO或者IN_SCFHEADER中
select * from in_sfcheader where MO_ID IN('001600044481'); SELECT * FROM in_sfcheader_temp where MO_ ...