Java How do you use the preference API? Where do these variables store?

前端 未结 1 1570
说谎
说谎 2021-02-14 14:58

Say I have the following

Preferences prefs = Preferences.userRoot().node(this.getClass().getName());

String ID1 = \"Test1\";

System.out.printl         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 15:49

    1. Yes, the value is persistent but only for the user. It won't be there for other users.
    2. This is OS specific. For Windows it uses the registry, for Linux I believe it uses hidden files in the user root, although I'm not 100% sure.
    3. You've got a pretty good example in your question.
    4. It is different, not better. Preferences are a way of transparently storing settings for an application. These settings may be updated in run time by a user (for example you could use prefs to store user specific settings). Preferences are not meant to be editable outside of the application. Properties files tend to store hard setting specific to an application. These settings are the same for each user and tend not to change often. Properties files are text files and tend to accompany an application on deployment. You can edit them easily using a text editor. It is fairly rare for an application to update properties files.

    0 讨论(0)
提交回复
热议问题