![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e415. Determining If a Preference Node ExistsA preference node is automatically created wheneverPreferences.node() , Preferences.userNodeForPackage() , or
Preferences.systemNodeForPackage() is called. To avoid creating a
node, you should first check to see if it exists.
try { // Check if a node exists boolean exists = Preferences.userRoot().nodeExists("/foo"); // false // Get the node Preferences.userRoot().node("/foo"); // Getting a non-existent node automatically creates it exists = Preferences.userRoot().nodeExists("/foo"); // true // Remove the node Preferences prefs = Preferences.userRoot().node("/foo"); prefs.removeNode(); // The following would cause an IllegalStateException //exists = prefs.nodeExists("/foo"); // Use the following to determine if the node has been removed exists = prefs.nodeExists(""); // false } catch (BackingStoreException e) { }
e412. Creating a Preference Node e413. Retrieving a Preference Node e414. Removing a Preference Node e416. Retrieving the Parent and Child Nodes of a Preference Node e417. Finding a Preference in a Preference Tree
© 2002 Addison-Wesley. |