Example usage for java.util.prefs Preferences put

List of usage examples for java.util.prefs Preferences put

Introduction

In this page you can find the example usage for java.util.prefs Preferences put.

Prototype

public abstract void put(String key, String value);

Source Link

Document

Associates the specified value with the specified key in this preference node.

Usage

From source file:Main.java

public static void main(String[] args) {
    Preferences p = Preferences.userRoot();
    p.put(REALKEY, "bar");

    System.out.println(p);//from ww  w.j a v a2  s . co m
    System.out.println(p.get(REALKEY, "key"));

    p = Preferences.systemRoot();
    p.put(REALKEY, "key 2");

    System.out.println(p);
    System.out.println(p.get(REALKEY, "default"));
}

From source file:Main.java

public static void main(String[] args) {
    String PREF_KEY = "org.username";
    // Write Preferences information to HKCU (HKEY_CURRENT_USER),HKCU\Software\JavaSoft\Prefs\
    Preferences userPref = Preferences.userRoot();
    userPref.put(PREF_KEY, "a");

    System.out.println("Preferences = " + userPref.get(PREF_KEY, PREF_KEY + " was not found."));

    // Write Preferences information to HKLM (HKEY_LOCAL_MACHINE),HKLM\Software\JavaSoft\Prefs\
    Preferences systemPref = Preferences.systemRoot();
    systemPref.put(PREF_KEY, "b");

    System.out.println("Preferences = " + systemPref.get(PREF_KEY, PREF_KEY + " was not found."));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.println("Node's absolute path: " + myPrefs.absolutePath());

}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.println("userNodeForPackage: " + Preferences.userNodeForPackage(PreferenceExample.class));

}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.println("Node's name: " + myPrefs.name());
    System.out.println("Node's parent: " + myPrefs.parent());
    System.out.println("NODE: " + myPrefs);

}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    for (String s : myPrefs.keys()) {
        System.out.println("" + s + "= " + myPrefs.get(s, ""));
    }/*w  ww .j  a v a2 s  .  com*/

}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.print("Node's keys: ");
    for (String s : myPrefs.keys()) {
        System.out.print(s + "");
    }/*from  www .j a  v a 2 s  .  c o m*/
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    FileOutputStream fos = new FileOutputStream("prefs.xml");

    myPrefs.exportSubtree(fos);/*  w w w.  j  a v a 2s .  c om*/
    fos.close();

}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.print("Node's children: ");
    for (String s : myPrefs.childrenNames()) {
        System.out.print(s + "");
    }//from   w  w w.j av a  2  s  .  c  o m

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);
    prefs.put("key1", "value1");
    prefs.put("key2", "value2");
    prefs.putInt("intValue", 4);
    prefs.putBoolean("booleanValue", true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;//from  www.  j  a  v  a 2 s.co m
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    System.out.println(prefs.getInt("booleanValue", 0));
}