I'm writing a java application that contains a lot of savable settings. Basically my config structure looks like this:
Config |_ game 1 |_ Game name: blah... |_ Player name: alice |_ Player name: bob |_ other settings... |_ game 2 |_ Game name: hah |_ Player name: alice |_ Player name: bob |_ other settings... |_ game n....
You got the idea. I tried use xml but working with dom4j is a pain especially there are a lot of child nodes with the same name in different and same parent nodes and I need to change them a lot. So far the most hassle-less way I discover is use a plain text file like
[Game 1] Game name: blah Player name: alice Player name: bob ... [Game 2] ...
But I feel like this is very rudimentary. So what is the best or standard practice in industry for maintaining config files in java?
EDIT : I'd like the solution to be portable, like copy a file from one computer to another will not break the program. (Sorry forget mention this ahead.)
The best way to store settings/preferences in java is to use the Preferences API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With