确定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 祝福语驱散霉运的话简短