Apache-commons-config Properties Configuration: comments after the last property are lost

I am using PropertiesConfiguration to edit a properties file. This allows me to post comments. Everything works fine, except for comments that appear after the last key.

For example, the input file

# *** A comment
GameCheck.no=No
**#  end coment**

The conclusion is as follows. He lost the comment that came after the last key.

# *** A comment
GameCheck.no = myvar

Code as below.

package trials;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.PropertiesConfigurationLayout;

import java.io.FileWriter;
import java.io.IOException;

public class EditVersion {

    public static void main(String[] args) {

        try {
            PropertiesConfiguration config =  new PropertiesConfiguration("C:\\try\\in.properties");
            config.setProperty("application.version", "myvar");
            PropertiesConfigurationLayout layout = config.getLayout();

            config.save( new FileWriter( "c:/try/out.props"));
        } catch (ConfigurationException e) {

        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

The work around is adding a dummy property to the end of the file. Right?

+5
source share
2 answers

This is a bug that should be reported in the JIRA project :)

https://issues.apache.org/jira/browse/CONFIGURATION

+2

** **# end coment**, .

, , .

0

All Articles