/**
* 获取配置文件中指定属性的值
* @param key 配置文件中的属性名称
* @return 返回属性的值
*/
protected String getProperty(String key)
{
String[] configValue = getProperties(key);
return configValue[0];
}
/**
* 获取配置文件中所有属性的相应值
* @return 返回属性的名称及值的数组
*/
protected String[] getProperties(String key)
{
String[] configValue = null;
try{
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new XMLConfiguration("aaa.xml"));
config.addConfiguration(new XMLConfiguration("bbb.xml"));
configValue = config.getStringArray(key);
}catch(ConfigurationException e)
{
log.error("读配置文件:",e);
e.printStackTrace();
}
return configValue;
}common-configuration读取xml,properties文件(二)
最新推荐文章于 2023-04-18 10:04:05 发布
本文介绍了一种从配置文件中读取属性值的方法,并提供了两个关键函数:`getProperty`用于获取指定属性的值,`getProperties`则返回所有与指定键相关的属性值数组。文章详细展示了如何使用`CompositeConfiguration`来整合多个XML配置文件。
2959

被折叠的 条评论
为什么被折叠?



