Though java.util.properties allows reading and writing properties file, the writing does not preserve the formatting. Not surprising, because it is not tied to
java.util.properties
The best answer contains a small mistake: The line:
PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
Must be replaced by:
PropertiesConfigurationLayout layout = config.getLayout();