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
You can have a look to the Apache Commons Configuration, that contains PropertiesConfiguration class.
However, as I have never used it, I don't know if it preserves the comments and formatting...