e414. removing a preference node.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 34 行
TXT
34 行
Removing a preference node will remove all of the node's descendants.
See also e415 Determining If a Preference Node Exists.
try {
// First check to see if the node is already removed;
// otherwise, getting the node will automatically create it
boolean exists = Preferences.userRoot().nodeExists("/foo"); // false
if (!exists) {
// Get the node
Preferences prefs = Preferences.userRoot().node("/foo");
// Remove the node
prefs.removeNode();
// Trying to remove it again would cause an IllegalStateException
//prefs.removeNode();
}
// Create a node with a child
Preferences prefs = Preferences.userRoot().node("/foo/child");
exists = Preferences.userRoot().nodeExists("/foo"); // true
exists = Preferences.userRoot().nodeExists("/foo/child"); // true
// Remove the parent node
Preferences.userRoot().node("/foo").removeNode();
// Both parent and child are removed
exists = Preferences.userRoot().nodeExists("/foo"); // false
exists = Preferences.userRoot().nodeExists("/foo/child"); // false
} catch (BackingStoreException e) {
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?