Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to maintain a config file for java application [closed]

Tags:

java

config

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.)

like image 943
YankeeWhiskey Avatar asked Jul 11 '13 12:07

YankeeWhiskey


1 Answers

The best way to store settings/preferences in java is to use the Preferences API.

like image 160
jtahlborn Avatar answered Sep 21 '22 18:09

jtahlborn