Results 1 to 4 of 4

Thread: Saving prefs

  1. #1
    DC200 is offline Member
    Join Date
    Dec 2008
    Posts
    49
    Rep Power
    0

    Default Saving prefs

    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?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    Quote Originally Posted by DC200 View Post
    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?

  3. #3
    DC200 is offline Member
    Join Date
    Dec 2008
    Posts
    49
    Rep Power
    0

    Default

    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.

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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.

Similar Threads

  1. Hi! Saving data??
    By Gahstanz in forum New To Java
    Replies: 1
    Last Post: 06-29-2010, 06:29 AM
  2. Saving JTextArea to .txt
    By AwesomeStorm in forum New To Java
    Replies: 8
    Last Post: 05-29-2010, 07:14 AM
  3. Saving JFrame
    By jralexander in forum New To Java
    Replies: 7
    Last Post: 12-03-2008, 09:19 PM
  4. Saving changes done through a program
    By xcallmejudasx in forum New To Java
    Replies: 0
    Last Post: 12-02-2008, 04:53 PM
  5. Saving Variables
    By Fish in forum New To Java
    Replies: 6
    Last Post: 06-25-2007, 08:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •