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?
Asked
Active
Viewed 876 times
1
-
Read the "saving" section here: http://commons.apache.org/proper/commons-configuration/howto_properties.html – Nir Alfasi Aug 06 '13 at 01: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. – rjurney Aug 06 '13 at 23:50
1 Answers
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();

sasha.j
- 54
- 3