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
GameCheck.no=No
**
The conclusion is as follows. He lost the comment that came after the last key.
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();
}
}
}
The work around is adding a dummy property to the end of the file. Right?
Jayan source
share