(下面注释掉的那段代码给恢复, 就能把写入的注册键值删除, 很方便啊)
至于读注册表项, 比写还方便, 查JDK API文档吧..
// PrefsDemo.java
import java.io.*;
import java.util.prefs.*;
public class PrefsDemo {
public static void main(String args[])
{
String keys[] ={"sunway","copyright","author"};
String values[] ={"sunway technology company","copyright 2002","turbochen@163.com"};
/* 建立一个位于user root下的/com/sunway/spc节点参数项*/
Preferences prefsdemo =Preferences.userRoot().node("/com/sunway/spc");
/* 储存参数项*/
for (int i=0 ; i keys.length; i++)
{
prefsdemo.put(keys[i], values[i]);
}
/* 导出到XML文件 */
try
{
FileOutputStream fos = new FileOutputStream("prefsdemo.xml");
prefsdemo.exportNode(fos);
} catch (Exception e)
{
System.err.println("Cannot export nodes: " + e);
}
/* 去掉注释可以清除注册表中的参数项*/
/*try
{
prefsdemo.removeNode();
} catch (BackingStoreException e)
{
}*/
}
}