确定Java中是否存在首选项节点
为了确定Java中是否存在一个首选项节点,我们使用该nodeExists()方法。该nodeExists()方法返回一个布尔值。当指定的首选项节点与此节点位于同一棵树中时,它将返回true。
声明-java.util.prefs.Preferences.remove()方法声明如下-
public abstract boolean nodeExists(String pathname)throws BackingStoreException
其中pathname是需要确定其存在的节点的路径名。
让我们来看一个确定Java中是否存在首选项节点的程序-
示例
import java.util.prefs.Preferences;
public class Example {
public static void main(String[] args) throws Exception {
boolean exist = Preferences.userRoot().nodeExists("/node");
System.out.println("Checking node existence before creation: "+exist);
Preferences.userRoot().node("/node");
exist = Preferences.userRoot().nodeExists("/node");
System.out.println("Checking node existence after creation: "+exist);
}
}输出结果
Checking node existence before creation: false Checking node existence after creation: true Dec 26, 2018 7:12:10 AM java.util.prefs.FileSystemPreferences$1 run INFO: Created user preferences directory.
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语