Example usage for java.util.prefs Preferences userRoot

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

Introduction

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

Prototype

public static Preferences userRoot() 

Source Link

Document

Returns the root preference node for the calling user.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue"); // false

    Preferences.userRoot().node("/yourValue");

    exists = Preferences.userRoot().nodeExists("/yourValue"); // true

    Preferences prefs = Preferences.userRoot().node("/yourValue");
    prefs.removeNode();//from w  ww.j av  a 2s  .c  om

    // exists = prefs.nodeExists("/yourValue");

    exists = prefs.nodeExists(""); // false
}

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:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue");
    if (!exists) {
        Preferences prefs = Preferences.userRoot().node("/yourValue");
        prefs.removeNode();/*from   ww w .ja  va  2s  . co  m*/
        // prefs.removeNode();
    }
    Preferences prefs = Preferences.userRoot().node("/yourValue/child");
    exists = Preferences.userRoot().nodeExists("/yourValue");
    exists = Preferences.userRoot().nodeExists("/yourValue/child");

    Preferences.userRoot().node("/yourValue").removeNode();

    exists = Preferences.userRoot().nodeExists("/yourValue");
    exists = Preferences.userRoot().nodeExists("/yourValue/child");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue"); // false
    if (!exists) {
        Preferences prefs = Preferences.userRoot().node("/yourValue");
        prefs.removeNode();/* ww  w  . j  a va 2 s.co  m*/
        // prefs.removeNode();
    }
    Preferences prefs = Preferences.userRoot().node("/yourValue/child");
    exists = Preferences.userRoot().nodeExists("/yourValue"); // true
    exists = Preferences.userRoot().nodeExists("/yourValue/child"); // true

    Preferences.userRoot().node("/yourValue").removeNode();

    exists = Preferences.userRoot().nodeExists("/yourValue"); // false
    exists = Preferences.userRoot().nodeExists("/yourValue/child"); // false
}

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, ""));
    }/*from w w w  . jav  a 2s  .  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);//from w  w  w  .  j  ava 2  s.c  o m
    fos.close();

}

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 .java 2 s  .c  o  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: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  ww w  . jav a  2s. c  o m*/
}