使用common-configuration读取xml,properties文件

http://commons.apache.org/configuration/apidocs/index.html
Commons Configuration provides a generic configuration interface which enables a Java application to

read configuration data from a variety of sources.

PropertiesConfiguration Loads configuration values from a properties file.
XMLConfiguration Takes values from an XML document.
INIConfiguration Loads the values from a .ini file as used by Windows.
PropertyListConfiguration Loads values from an OpenStep .plist file. XMLPropertyListConfiguration is

also available to read the XML variant used by Mac OS X.
JNDIConfiguration Using a key in the JNDI tree, can retrieve values as configuration properties.
BaseConfiguration An in-memory method of populating a Configuration object.
HierarchicalConfiguration An in-memory Configuration object that is able to deal with complex

structured data.
SystemConfiguration A configuration using the system properties
ConfigurationConverter Takes a java.util.Properties or an

org.apache.commons.collections.ExtendedProperties and converts it to a Configuration object.


1.读取XML文件中内容


global.xml:

2.读取properties文件

 

global.properties:

 

 

3.当有多个配置文件时,就利用ConfigurationFactory对象来访问多个不同的配置资源

ConfigurationFactory可以组合多个配置资源。然后我们就可以像访问单个资源文件一样来访问他们中的属性。首

先,我们需要创建一个xml文件来告诉工厂哪些文件将要被加载。下面是一个例:
 <?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
  <properties fileName="usergui.properties"/>
</configuration>
ConfigurationFactory的定义文件是一个普通的xml文件.根元素是configuration.他饱含的子元素制定了需要装载

的配置资源.properties是元素之一,他用来包含属性文件

 

 

additional-xml-configuration.xml:

 


或者采用另外一种方法:  用到了:CompositeConfiguration,手动加上两个配置文件

 

转帖出处:http://blog.csdn.net/pengchua/archive/2007/12/21/1957069.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值