views:

42

answers:

4

Hi, I am working on a project and I need to save user configuration. The configuration is a set of Jchechboxes I need to store their state (true, false). Which do you think is the better way of saving it, in a file and if yes in what (ini, cfg, txt), or it is better to serialize the object with the states?? Or if there is another way, please tell me :)

Cheers

+1  A: 

How about a Properties file?

Konrad Garus
+1  A: 

It depends if you need to access the variables many times, and when: at the start of the application or during runtime?

If this configuration is user-related maybe you want to keep separate configuration for each user serialized on a Database so you can load them dynamically when a user loads the form that displays the checkboxes.

If there's just one possible configuration for one user (or such) maybe you should just put everything in a text file (the extension doesn't matter: ini,cfg,txt,lol anything you want) just simplify your life by using standard Java configuration access using the Properties class: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html

Lex
the you better go with a single properties file
Lex
+1  A: 

If you decided to store the properties as a serialized object then you will make changing the implementation of the gui much harder and thus less portable. If you save them in a text file then you are free to change the GUI implementation without any disruption to the user, whilst allowing the user to keep their saved properties.

As such, I would always recommend storing preferences in a properties type file. The Properties API, and related commons classes are pretty simple to use.

Joel
A: 

The best method is to use java.util.prefs to store user preferences

Paul McKenzie