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
I once saw a class to do this with INI files but can't find the link anymore. If you can't find anything else, you can try DecentXML. I wrote this XML parser with the specific design goal to preserve the original formatting 100% (i.e. with comments, weird spaces in elements or around the root element, everything).
During parsing the resulting XML document, you just have to remember the elements which contain the value for your options and replace the text node in them. When you save, nothing untouched will change in any way.