I've got an application that can launch n threads, each with its own settings. I'm passing values to these threads through a serializable object called Properties that contains public variables.
Right now, I'm saving my application preferences by adding all Properties objects to a collection and then writing them to a file. However, I'm starting to wonder whether or not I should be using java.util.prefs.Preferences and saving my preferences to an XML file instead.
Reading objects from a file is simple and straightforward when it comes to starting the threads, but modifying and saving the collection of objects is a pain. Should I switch to java.util.prefs.Preferences or not?
Why not try it both ways and see which one you like better?
Originally Posted by DC200
Is it bad practice to save preferences as serializable objects written to a file? It's fast and easy, but the XML option still seems cleaner to me.
If you use Preferences, they may get persisted independent of the xml import/export feature. On unix systems, they'll get written into the user's home directory in a hidden .java directory. On Windows, they'll get persisted to the Window's registry. This potential side effect may be of concern if all you're trying to do is read/write xml files.