在我的项目中,我们有一个属性文件,其中包含如下一些条目:
#Data key entries
datakey001
datakey321
datakey451
someotherkey
其实它不是一个键值对,而是一个键列表。使用 java.util.Properties
我能够使用 Properties.stringPropertyNames()
获得它。
现在我们正在迁移到 Apache Commons Configuration,我在这个库中找不到任何功能来获取所有这些 key ,就像我以前使用 java.util.Properties
获取的那样。
在 apache commons 配置中有没有什么方法可以在不更改属性文件结构的情况下获取所有这些 key ?
编辑:我试过如下使用 Configuration.getKeys()
,但输出为空。
Configuration propertiesConfig = new PropertiesConfiguration("C:\\proj\\myprops.properties");
Iterator<String> it = propertiesConfig.getKeys();
while(it.hasNext()) {
System.out.println(it.next());
}
最佳答案
您可以使用Configuration.getKeys()
method为了那个原因。
关于java - 如何使用 Apache commons 配置获取属性文件中的条目列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32086978/