Java删除操作注册表
示例代码如下:
Preferences userData = Preferences.userRoot();
Scanner input = new Scanner(System.in);
List<String> childrenNamesList = Arrays.asList(userData.childrenNames());
Map<String, Preferences> preferencesMap = new HashMap<>();
childrenNamesList.forEach(s -> preferencesMap.put(s,Preferences.userRoot().node(s)));
if(childrenNamesList.isEmpty()){
System.out.println("注册表中相关节点为空,无需删除!");
}
System.out.println("需要删除的注册表节点:");
String deleteName = "";
deleteName = input.nextLine();
try {
preferencesMap.get(deleteName).removeNode();
preferencesMap.remove(deleteName);
}catch (Exception e){
System.out.println("节点删除失败!可能节点【"+deleteName+"】为空!");
return;
}
System.out.println("删除节点" + deleteName + "成功!");