Retrieving the Parent and Child Nodes of a Preference Node - Java Native OS

Java examples for Native OS:Preference

Description

Retrieving the Parent and Child Nodes of a Preference Node

Demo Code

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

public class Main {
  public static void main(String[] argv) {
    // Get a node
    Preferences prefs = Preferences.userNodeForPackage(java.lang.String.class);

    // Get the parent
    Preferences node = prefs.parent(); // /java
    node = node.parent(); // null

    // Get the names for nodes under java.lang
    String[] names = null;//from   w  ww  .  ja  v  a 2  s  . c o  m
    try {
      names = prefs.childrenNames();
    } catch (BackingStoreException e) {
    }

    // Get the child nodes using the names
    for (int i = 0; i < names.length; i++) {
      node = prefs.node(names[i]);
    }
  }
}

Result


Related Tutorials