给定Configuration对象,如何创建PropertiesConfiguration对象?

时间:2013-08-06 00:51:53

标签: java configuration properties-file apache-commons-config

我有一个返回Configuration对象的方法。我需要实例化一个PropertiesConfig对象以将其保存到磁盘。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

您是否尝试过使用复制方法?这个例子对我有用:

    XMLConfiguration conf1 = new XMLConfiguration("table1.xml");
    XMLConfiguration conf2 = new XMLConfiguration("table2.xml");

    // Create and initialize the node combiner
    NodeCombiner combiner = new UnionCombiner();
    combiner.addListNode("table");  // mark table as list node
                // this is needed only if there are ambiguities

    // Construct the combined configuration
    CombinedConfiguration cc = new CombinedConfiguration(combiner);
    cc.addConfiguration(conf1, "tab1");
    cc.addConfiguration(conf2);

    PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");

    config.copy(cc);
    config.save();