【发布时间】:2015-11-12 05:59:56
【问题描述】:
在我的项目中,我们有一个属性文件,其中包含以下条目:
#Data key entries
datakey001
datakey321
datakey451
someotherkey
其实它不是一个键值对,而是一个键列表。使用java.util.Properties 我可以使用Properties.stringPropertyNames() 得到这个。
现在我们正在迁移到 Apache Commons Configuration,我无法在这个库中找到任何功能来获取所有这些密钥,就像我以前使用 java.util.Properties 获取的那样。
在 apache commons config 中有什么方法可以让我在不更改属性文件结构的情况下获取所有这些键?
编辑:我尝试使用Configuration.getKeys(),如下所示,但输出为空。
Configuration propertiesConfig = new PropertiesConfiguration("C:\\proj\\myprops.properties");
Iterator<String> it = propertiesConfig.getKeys();
while(it.hasNext()) {
System.out.println(it.next());
}
【问题讨论】:
标签: java apache-commons-config