1

I have a method that returns a Configuration object. I need to instantiate a PropertiesConfig object to save this to disk. How can I do so?

2
  • Read the "saving" section here: commons.apache.org/proper/commons-configuration/… Commented Aug 6, 2013 at 1:04
  • Thanks - I've read that, but the Config object I have is actually a CombinedConfiguration, and has no save method. I need to 'converet' it to a properties config and save it as a properties file. Commented Aug 6, 2013 at 23:50

1 Answer 1

2

Have you tried using copy method? This example works for me:

    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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.