打印首选项节点的子代 [英] Printing children of a preference node

查看:54
本文介绍了打印首选项节点的子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印首选项节点的子代.我编写了以下代码:

I want to print the children of a preference node. I've wrote the following code:

private void printOracleDefaults() {
    Preferences p = Preferences.userRoot();
    p = p.node("/HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE");
    try {
       for(String s : p.childrenNames())
          System.out.println(s);
    } catch (BackingStoreException e) {
       //bla bla..
       e.printStackTrace();
    }
}

尽管ORACLE有子级,但上面的方法不会打印任何内容:

The method above doesn't print anything, although ORACLE has children:

我在做什么错或误解?

更新:

我写了p = p.node("HKEY_LOCAL_MACHINE/SOFTWARE");

代替

p = p.node("HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE");

当我打印p的孩子时,我得到了:ORACLE!这怎么可能?那其他孩子呢? (有..我通过注册表编辑器看到了它们)

and when I printed the childrens of p I got: ORACLE! How is it possible? What about all other childrens? (There are.. I saw them through the Registry Editor)

看起来它存储的是先前存储在/SOFTWARE旁边的先前运行中的先前值.

Looks like it was storing the previous values from the previous runs that were attached next to /SOFTWARE.

推荐答案

我认为您应该在这里使用Preferences.systemRoot()而不是Preferences.userRoot().后者映射到HKEY_CURRENT_USER.

I think you should use Preferences.systemRoot() instead of Preferences.userRoot() here. The latter maps to HKEY_CURRENT_USER.

在Windows中,路径应为HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE,然后像HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE一样将其转义到字符串中.

With Windows, the path should be HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE and then you escape it inside the String like HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE.

注意:我自己还没有尝试过.

Note: I've not tried this myself.

这篇关于打印首选项节点的子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆