<b>Jakarta-Common-Configuration操纵笔记</b>[Java编程]
本文“<b>Jakarta-Common-Configuration操纵笔记</b>[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
这是一个读取配置文件的工具包.
下载地址 : http://commons.apache.org/configuration/
A.读取XML配置文件:
<config>
<ip>10.10.1.1</ip>
<account>jini</account>
<password>jakarta99</password>
<roles>
<role>admin</role>
<role>manager</role>
<role>user</role>
</roles>
</config>
测试代码:
package demo;
import java.util.List;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
public class XMLConfigurationDemo ...{
public static void main(String[] args) throws ConfigurationException ...{
Configuration config = new XMLConfiguration(XMLConfigurationDemo.class
.getResource("/demo/system-config.xml"));
String ip = config.getString("ip");
String account = config.getString("account");
String password = config.getString("password");
List<?> roles = config.getList("roles.role");
System.out.println("IP: " + ip);
System.out.println("Account: " + account);
System.out.println("Password: " + password);
System.out.println("★★★★★ Roles Begin ★★★★★");
for (int i = 0; i < roles.size(); i++) ...{
System.out.println("Role: " + roles.get(i));
}
System.out.println("★★★★★ Roles End ★★★★★");
}
}
B.读取Properties配置文件:
ip=10.10.1.1
account=jini
password=jakarta99
role1=admin
role2=manager
role3=user
colors.pie = #FF0000, #00FF00, #0000FF
以上是“<b>Jakarta-Common-Configuration操纵笔记</b>[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |