确定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 红包祝福语简短10字
18 周六早晨祝福语简短