【发布时间】:2012-08-12 00:17:30
【问题描述】:
使用以下属性文件:
foo=hello, world!
bar=first,second
我想以字符串形式检索第一项,以数组形式检索第二项。我原以为 getString 与 getStringArray 会处理这个问题,但它不会 - getString("foo") 只是在逗号之前获取所有内容,即“你好”。
如果我使用 setDelimiterParsingDisabled 禁用分隔符解析,foo 很好,但这也会改变 getStringArray("bar") 的行为以返回单元素数组!
我找不到如何明确告诉它我希望它如何解释单个配置项,无论是作为字符串还是作为数组。我不想将配置项放入具有不同分隔符规则的单独配置文件中,我更喜欢使用逗号作为 getStringArray 案例的分隔符。
详细地说,这个 sn-p 打印 hello - 2 或 hello, world! - 1 - 我希望它打印 hello, world! - 2 !
AbstractFileConfiguration config = new PropertiesConfiguration();
config.setFileName("C:\\temp\\temp.properties");
//config.setDelimiterParsingDisabled(true);
config.load();
System.out.println(config.getString("foo") + " - " + config.getStringArray("bar").length);
【问题讨论】:
-
这里是相应的公共配置问题:[issues.apache.org/jira/browse/CONFIGURATION-26]
-
修复您的链接 - CONFIGURATION-26。实际上,我在询问 SO... 后不久就对此发表了评论...
标签: java configuration apache-commons-config