javaapache-commonsapache-commons-config

How to get properties without it being delimited?


I'm using commons-configuration v1.10 and I'm using the class PropertiesConfiguration to read in my applications properties. I have a property which has commas in it, but when I read it in, it gets delimited, and I can't figure out how to get it not to.

It spits back the property all in order and commas included, but the reason why it's being a problem is because I get '[' and ']' surrounding it.

AbstractConfiguration has a function, setDelimiterParsingDisabled(), that disables delimiting, but I couldn't find a class which implemented it to read property files.

private static String readProperty(String property) {
    try {
        Configuration configuration = new PropertiesConfiguration(propertiesFile);
        return configuration.getProperty(property).toString();
    }
    catch(ConfigurationException e) {
        System.out.println("Issue reading " + property + " property");
        e.printStackTrace();
        System.exit(1);
        return "";
    }
}

Solution

  • It doesn't look like I can use Apache Commons or PropertiesConfiguration to retrieve properties without it being delimited. However, java.util.Properties does not have this issue, so used that instead of PropertiesConfiguration.

    MKYong has a good example of how to set it up, http://www.mkyong.com/java/java-properties-file-examples/