确定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 送给学长毕业祝福语简短