e415. determining if a preference node exists.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 26 行

TXT
26
字号
A preference node is automatically created whenever Preferences.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) {
    }

 Related Examples 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?