A better class to update property files?

后端 未结 8 1996
不思量自难忘°
不思量自难忘° 2020-12-01 10:27

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

8条回答
  •  Happy的楠姐
    2020-12-01 10:43

    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.

提交回复
热议问题