greenLizard
greenLizard

Reputation: 2346

Application configuration save to file or object serialization

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

Upvotes: 1

Views: 2040

Answers (4)

Paul McKenzie
Paul McKenzie

Reputation: 20094

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

Upvotes: 1

Joel
Joel

Reputation: 30166

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.

Upvotes: 1

OverLex
OverLex

Reputation: 2521

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

Upvotes: 1

Konrad Garus
Konrad Garus

Reputation: 54045

How about a Properties file?

Upvotes: 1

Related Questions