Dev
Dev

Reputation: 13773

Direct way to convert org.apache.commons.configuration.Configuration to java.util.Properties

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?

Upvotes: 3

Views: 2503

Answers (1)

Arnaud
Arnaud

Reputation: 17534

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.

Upvotes: 7

Related Questions