Save user data where?

Discussion in 'Java' started by Karsten Wutzke, Apr 18, 2007.

  1. Hi all!

    I wish to save some user data (editable via GUI) on a per user basis.

    Is there any nice mechanism in Java that puts such info into an
    appropriate place? If I have to do that manually, what would be a nice
    place to save some small files with bothering the user? Or shall I
    force every user to specify a directory?

    Karsten
     
    Karsten Wutzke, Apr 18, 2007
    #1
    1. Advertising

  2. Karsten Wutzke wrote:
    > Hi all!
    >
    > I wish to save some user data (editable via GUI) on a per user basis.
    >
    > Is there any nice mechanism in Java that puts such info into an
    > appropriate place? If I have to do that manually, what would be a nice
    > place to save some small files with bothering the user? Or shall I
    > force every user to specify a directory?
    >
    > Karsten
    >


    Look at the system property user.home.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Apr 18, 2007
    #2
    1. Advertising

  3. On 18 Apr., 19:19, Knute Johnson <>
    wrote:
    > Karsten Wutzke wrote:
    > > Hi all!

    >
    > > I wish to save some user data (editable via GUI) on a per user basis.

    >
    > > Is there any nice mechanism in Java that puts such info into an
    > > appropriate place? If I have to do that manually, what would be a nice
    > > place to save some small files with bothering the user? Or shall I
    > > force every user to specify a directory?

    >
    > > Karsten

    >
    > Look at the system property user.home.
    >
    > --
    >
    > Knute Johnson
    > email s/nospam/knute/


    I know this. But I don't want to create files or directories "unasked"
    which will clutter the user's home dir and make some users really mad
    (as I would be).

    Karsten
     
    Karsten Wutzke, Apr 18, 2007
    #3
  4. Karsten Wutzke schrieb:
    > I wish to save some user data (editable via GUI) on a per user basis.
    >
    > Is there any nice mechanism in Java that puts such info into an
    > appropriate place? If I have to do that manually, what would be a nice
    > place to save some small files with bothering the user? Or shall I
    > force every user to specify a directory?


    Sounds like you need java.util.prefs.Preferences.

    You can get a handle to the user's preferences by:
    Preferences prefs =
    Preferences.userNodeForPackage(my.package.Main.class);
    Java keeps the user's preferences in a platform-specific place:
    (*) for Windows: in a certain user-specific branch of the registry
    (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    But you don't have to care about those details.

    You read/write specific key/value like this:
    String value = prefs.get(key);
    prefs.get(key, value);

    For more details see the API docs
    <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html#userNodeForPackage(java.lang.Class)>

    --
    Thomas
     
    Thomas Fritsch, Apr 18, 2007
    #4
  5. Karsten Wutzke

    Jason Cavett Guest

    On Apr 18, 1:36 pm, Thomas Fritsch <>
    wrote:
    > Karsten Wutzke schrieb:
    >
    > > I wish to save some user data (editable via GUI) on a per user basis.

    >
    > > Is there any nice mechanism in Java that puts such info into an
    > > appropriate place? If I have to do that manually, what would be a nice
    > > place to save some small files with bothering the user? Or shall I
    > > force every user to specify a directory?

    >
    > Sounds like you need java.util.prefs.Preferences.
    >
    > You can get a handle to the user's preferences by:
    > Preferences prefs =
    > Preferences.userNodeForPackage(my.package.Main.class);
    > Java keeps the user's preferences in a platform-specific place:
    > (*) for Windows: in a certain user-specific branch of the registry
    > (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    > But you don't have to care about those details.
    >
    > You read/write specific key/value like this:
    > String value = prefs.get(key);
    > prefs.get(key, value);
    >
    > For more details see the API docs
    > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.h...)>
    >
    > --
    > Thomas


    There wouldn't be any problem with permissions using this method,
    would there? (AKA - The user can't write to the registry.)
     
    Jason Cavett, Apr 18, 2007
    #5
  6. Karsten Wutzke

    Guest

    On Apr 18, 2:36 pm, Jason Cavett <> wrote:
    > On Apr 18, 1:36 pm, Thomas Fritsch <> wrote:
    > > Sounds like you need java.util.prefs.Preferences.
    > >
    > > You can get a handle to the user's preferences by:
    > > Preferences prefs =
    > > Preferences.userNodeForPackage(my.package.Main.class);
    > > Java keeps the user's preferences in a platform-specific place:
    > > (*) for Windows: in a certain user-specific branch of the registry
    > > (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    > > But you don't have to care about those details.

    >
    > > You read/write specific key/value like this:
    > > String value = prefs.get(key);
    > > prefs.get(key, value);

    >
    > > For more details see the API docs
    > > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    > > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.h...)>

    >
    > There wouldn't be any problem with permissions using this method,
    > would there? (AKA - The user can't write to the registry.)


    The default Sun implementation on Windows stores preferences in a node
    under HKEY_CURRENT_USER, which is always writable by the current user
    and is normally made part of the user's profile, whether local or
    roaming.

    So no, not really.
     
    , Apr 18, 2007
    #6
  7. Karsten Wutzke wrote:
    > On 18 Apr., 19:19, Knute Johnson <>
    > wrote:
    >> Karsten Wutzke wrote:
    >>> Hi all!
    >>> I wish to save some user data (editable via GUI) on a per user basis.
    >>> Is there any nice mechanism in Java that puts such info into an
    >>> appropriate place? If I have to do that manually, what would be a nice
    >>> place to save some small files with bothering the user? Or shall I
    >>> force every user to specify a directory?
    >>> Karsten

    >> Look at the system property user.home.
    >>
    >> --
    >>
    >> Knute Johnson
    >> email s/nospam/knute/

    >
    > I know this. But I don't want to create files or directories "unasked"
    > which will clutter the user's home dir and make some users really mad
    > (as I would be).
    >
    > Karsten
    >


    Then store it on a remote server. I really don't think that makes any
    sense but it accomplishes what you want; a file but not on the users
    computer.

    When I look in my Windoze computer home directory I can find 25 folders
    of stuff that applications have put there. That is where that kind of
    stuff belongs. I didn't look at my Linux home directory but I know
    there is a lot of application data there too.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Apr 18, 2007
    #7
  8. Thomas Fritsch wrote:
    > Karsten Wutzke schrieb:
    >> I wish to save some user data (editable via GUI) on a per user basis.
    >>
    >> Is there any nice mechanism in Java that puts such info into an
    >> appropriate place? If I have to do that manually, what would be a nice
    >> place to save some small files with bothering the user? Or shall I
    >> force every user to specify a directory?

    >
    > Sounds like you need java.util.prefs.Preferences.
    >
    > You can get a handle to the user's preferences by:
    > Preferences prefs =
    > Preferences.userNodeForPackage(my.package.Main.class);
    > Java keeps the user's preferences in a platform-specific place:
    > (*) for Windows: in a certain user-specific branch of the registry
    > (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    > But you don't have to care about those details.
    >
    > You read/write specific key/value like this:
    > String value = prefs.get(key);
    > prefs.get(key, value);
    >
    > For more details see the API docs
    > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html#userNodeForPackage(java.lang.Class)>
    >
    >


    I hadn't seen this before (where have I been?). Where does it store
    stuff on a Linux system?

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Apr 18, 2007
    #8
  9. Karsten Wutzke

    Jason Cavett Guest

    On Apr 18, 5:53 pm, wrote:
    > On Apr 18, 2:36 pm, Jason Cavett <> wrote:
    >
    >
    >
    > > On Apr 18, 1:36 pm, Thomas Fritsch <> wrote:
    > > > Sounds like you need java.util.prefs.Preferences.

    >
    > > > You can get a handle to the user's preferences by:
    > > > Preferences prefs =
    > > > Preferences.userNodeForPackage(my.package.Main.class);
    > > > Java keeps the user's preferences in a platform-specific place:
    > > > (*) for Windows: in a certain user-specific branch of the registry
    > > > (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    > > > But you don't have to care about those details.

    >
    > > > You read/write specific key/value like this:
    > > > String value = prefs.get(key);
    > > > prefs.get(key, value);

    >
    > > > For more details see the API docs
    > > > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    > > > <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.h...)>

    >
    > > There wouldn't be any problem with permissions using this method,
    > > would there? (AKA - The user can't write to the registry.)

    >
    > The default Sun implementation on Windows stores preferences in a node
    > under HKEY_CURRENT_USER, which is always writable by the current user
    > and is normally made part of the user's profile, whether local or
    > roaming.
    >
    > So no, not really.


    By "normally" do you mean that, assuming no problems, I can assume the
    settings will be saved on a per-user basis?
     
    Jason Cavett, Apr 19, 2007
    #9
  10. Knute Johnson wrote:
    > Thomas Fritsch wrote:
    >>
    >> Preferences prefs =
    >> Preferences.userNodeForPackage(my.package.Main.class);
    >> Java keeps the user's preferences in a platform-specific place:
    >> (*) for Windows: in a certain user-specific branch of the registry
    >> (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    >> But you don't have to care about those details.

    >
    > I hadn't seen this before (where have I been?). Where does it store
    > stuff on a Linux system?
    >

    On my Linux I found it in file
    $HOME/.java/.userprefs/my/package/prefs.xml

    And (by the way) on Windows it is in registry section
    HKEY_CURRENT_USER\Software\JavaSoft\prefs\my\package

    --
    Thomas
     
    Thomas Fritsch, Apr 19, 2007
    #10
  11. Thomas Fritsch wrote:
    > On my Linux I found it in file
    > $HOME/.java/.userprefs/my/package/prefs.xml

    $HOME/.java/.userPrefs/my/package/prefs.xml
    >
    > And (by the way) on Windows it is in registry section
    > HKEY_CURRENT_USER\Software\JavaSoft\prefs\my\package

    HKEY_CURRENT_USER\Software\JavaSoft\Prefs\my\package

    Sorry for the 2 typos...

    --
    Thomas
     
    Thomas Fritsch, Apr 19, 2007
    #11
  12. Thomas Fritsch wrote:
    > Thomas Fritsch wrote:
    >> On my Linux I found it in file
    >> $HOME/.java/.userprefs/my/package/prefs.xml

    > $HOME/.java/.userPrefs/my/package/prefs.xml
    >>
    >> And (by the way) on Windows it is in registry section
    >> HKEY_CURRENT_USER\Software\JavaSoft\prefs\my\package

    > HKEY_CURRENT_USER\Software\JavaSoft\Prefs\my\package
    >
    > Sorry for the 2 typos...
    >


    Thanks Thomas.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Apr 19, 2007
    #12
  13. Jason Cavett wrote:
    > On Apr 18, 5:53 pm, wrote:
    >> On Apr 18, 2:36 pm, Jason Cavett <> wrote:
    >>
    >>
    >>
    >>> On Apr 18, 1:36 pm, Thomas Fritsch <> wrote:
    >>>> Sounds like you need java.util.prefs.Preferences.
    >>>> You can get a handle to the user's preferences by:
    >>>> Preferences prefs =
    >>>> Preferences.userNodeForPackage(my.package.Main.class);
    >>>> Java keeps the user's preferences in a platform-specific place:
    >>>> (*) for Windows: in a certain user-specific branch of the registry
    >>>> (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    >>>> But you don't have to care about those details.
    >>>> You read/write specific key/value like this:
    >>>> String value = prefs.get(key);
    >>>> prefs.get(key, value);
    >>>> For more details see the API docs
    >>>> <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    >>>> <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.h...)>
    >>> There wouldn't be any problem with permissions using this method,
    >>> would there? (AKA - The user can't write to the registry.)

    >> The default Sun implementation on Windows stores preferences in a node
    >> under HKEY_CURRENT_USER, which is always writable by the current user
    >> and is normally made part of the user's profile, whether local or
    >> roaming.
    >>
    >> So no, not really.

    >
    > By "normally" do you mean that, assuming no problems, I can assume the
    > settings will be saved on a per-user basis?
    >


    Yes because for one thing the registry hive where the data is accessible
    for the current user is HKEY_CURRENT_USER (imagine that) so it would
    have to be on a per user basis because there is only one current user
    allowed with Windows XP. Plus, if you look into HKEY_USERS hive in the
    registry it will list all the SIDs of the users who have logged into the
    PC whose registry you are currently viewing. A user's registry data is
    part of the users profile so it will follow them (stored in ntuser.dat
    in every user's profile) and when they log in the HKEY_CURRENT_USER hive
    is just a link to the real location under HKEY_USERS. It is possible
    for permissions to be screwed up on HKEY_CURRENT_USER such that a user
    can't retain settings (like Windows Explorer folder view preferences)
    but normally each user can read/write to that location because they need
    to.

    I use the Preferences API in my program to store connection settings to
    a remote server in the registry for each other based on a recommendation
    I received from this group a few months ago. The API is so easy and
    after I experimented with it I was able to implement my code very quickly.
     
    Brandon McCombs, Apr 20, 2007
    #13
  14. Karsten Wutzke

    Jason Cavett Guest

    On Apr 19, 8:36 pm, Brandon McCombs <> wrote:
    > Jason Cavett wrote:
    > > On Apr 18, 5:53 pm, wrote:
    > >> On Apr 18, 2:36 pm, Jason Cavett <> wrote:

    >
    > >>> On Apr 18, 1:36 pm, Thomas Fritsch <> wrote:
    > >>>> Sounds like you need java.util.prefs.Preferences.
    > >>>> You can get a handle to the user's preferences by:
    > >>>> Preferences prefs =
    > >>>> Preferences.userNodeForPackage(my.package.Main.class);
    > >>>> Java keeps the user's preferences in a platform-specific place:
    > >>>> (*) for Windows: in a certain user-specific branch of the registry
    > >>>> (*) for Unix/Linux: in a certain hidden file in the user's home dir.
    > >>>> But you don't have to care about those details.
    > >>>> You read/write specific key/value like this:
    > >>>> String value = prefs.get(key);
    > >>>> prefs.get(key, value);
    > >>>> For more details see the API docs
    > >>>> <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html>
    > >>>> <http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.h...)>
    > >>> There wouldn't be any problem with permissions using this method,
    > >>> would there? (AKA - The user can't write to the registry.)
    > >> The default Sun implementation on Windows stores preferences in a node
    > >> under HKEY_CURRENT_USER, which is always writable by the current user
    > >> and is normally made part of the user's profile, whether local or
    > >> roaming.

    >
    > >> So no, not really.

    >
    > > By "normally" do you mean that, assuming no problems, I can assume the
    > > settings will be saved on a per-user basis?

    >
    > Yes because for one thing the registry hive where the data is accessible
    > for the current user is HKEY_CURRENT_USER (imagine that) so it would
    > have to be on a per user basis because there is only one current user
    > allowed with Windows XP. Plus, if you look into HKEY_USERS hive in the
    > registry it will list all the SIDs of the users who have logged into the
    > PC whose registry you are currently viewing. A user's registry data is
    > part of the users profile so it will follow them (stored in ntuser.dat
    > in every user's profile) and when they log in the HKEY_CURRENT_USER hive
    > is just a link to the real location under HKEY_USERS. It is possible
    > for permissions to be screwed up on HKEY_CURRENT_USER such that a user
    > can't retain settings (like Windows Explorer folder view preferences)
    > but normally each user can read/write to that location because they need
    > to.
    >
    > I use the Preferences API in my program to store connection settings to
    > a remote server in the registry for each other based on a recommendation
    > I received from this group a few months ago. The API is so easy and
    > after I experimented with it I was able to implement my code very quickly.- Hide quoted text -
    >
    > - Show quoted text -


    I just finished implementing Preferences for an application I'm
    working on. Wow...haha...that was so painless I felt like I did
    something wrong.

    ;-) Loving the Preferences.
     
    Jason Cavett, Apr 20, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. user
    Replies:
    1
    Views:
    775
    Bruce Barker
    Apr 4, 2005
  2. teo
    Replies:
    1
    Views:
    472
  3. BusyBoy
    Replies:
    2
    Views:
    612
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 31, 2006
  4. subhadip
    Replies:
    0
    Views:
    647
    subhadip
    Mar 28, 2007
  5. hell2heaven
    Replies:
    0
    Views:
    423
    hell2heaven
    Oct 26, 2008
Loading...

Share This Page