3

I am able to convert org.apache.commons.configuration.Configuration to java.util.Properties using:

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);
}

Assumption: keys and values are of String type.

Is there any direct way to convert Configuration to Properties?

Shubham
  • 2,847
  • 4
  • 24
  • 37
Dev
  • 13,492
  • 19
  • 81
  • 174

1 Answers1

7

ConfigurationConverter should do the job .

It has those two methods to convert in both directions :

Configuration getConfiguration(Properties props)

Convert a standard Properties class into a configuration class

and

Properties getProperties(Configuration config)

Convert a Configuration class into a Properties class.

Arnaud
  • 17,229
  • 3
  • 31
  • 44