开发者

Application configuration save to file or object serialization

开发者 https://www.devze.com 2022-12-23 15:51 出处:网络
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,

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 se开发者_开发问答rialize the object with the states?? Or if there is another way, please tell me :)

Cheers


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


How about a Properties file?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消