【问题标题】:Direct way to convert org.apache.commons.configuration.Configuration to java.util.Properties将 org.apache.commons.configuration.Configuration 转换为 java.util.Properties 的直接方法
【发布时间】:2016-07-18 06:08:21
【问题描述】:

我可以使用以下方法将org.apache.commons.configuration.Configuration 转换为java.util.Properties

Properties props = new Properties();
Configuration config = new PropertiesConfiguration(fileName);
Iterator iter = config.getKeys();

while (iter.hasNext()) {
    String key = (String) iter.next();
    String value = config.getString(key);
    props.put(key, value);
}

假设:键和值都是字符串类型。

有没有直接将Configuration转换为Properties的方法?

【问题讨论】:

    标签: java properties apache-commons-config


    【解决方案1】:

    ConfigurationConverter 应该可以胜任。

    它有这两种方法可以双向转换:

    配置 getConfiguration(Properties props)

    将标准的属性类转换为配置类

    属性 getProperties(配置配置)

    转换配置 类转换为属性类。

    【讨论】:

    • 这就是我要找的。谢谢..:)
    猜你喜欢
    • 2013-06-17
    • 2016-03-24
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 2011-06-14
    • 2014-11-15
    • 1970-01-01
    相关资源
    最近更新 更多