确定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.
热门推荐
1 聚餐会祝福语简短
8 庆双节祝福语简短
10 长辈钻石婚祝福语简短
11 生日牌祝福语英语简短
12 虎年台词祝福语大全简短
13 节日祝福语幽默简短的
14 元旦的祝福语简短 公司
15 关于开车的祝福语简短
16 中考祝福语简短卡片大全
17 妹妹生日祝福语简短唯美
18 中秋祝福语送朋友简短