| 发表于:2007-01-26 08:55:109楼 得分:50 |
/*读系统目录下的所有注册变量 path:为相对于prefs下面的注册表目录*/ public static void readallreg(string path){ path=stringutil.nulltoempty(path); preferences prefsdemo =preferences.systemroot().node(path); try{ string key1[]=prefsdemo.keys(); int len=key1.length; for(int i=0;i <len;i++){ string name=key1[i]; string value=prefsdemo.get(name,null); } }catch(exception e){ } } /*根据名称读注册表*/ public static boolean readregbyname(string regname,string path){ boolean bool=false; path=stringutil.nulltoempty(path); preferences prefsdemo =preferences.systemroot().node(path); try{ string key1[]=prefsdemo.keys(); int len=key1.length; for(int i=0;i <len;i++){ string name=key1[i]; if(regname.equals(name)){ return true; } } }catch(exception e){ } return bool; } /*写注册表*/ public static void writereg(string name,string value,string path){ path=stringutil.nulltoempty(path); preferences prefsdemo =preferences.systemroot().node(path); try{ prefsdemo.put(name,value); }catch(exception e){ } } /*删除所有注册项*/ public static void delallreg(string path){ path=stringutil.nulltoempty(path); preferences prefsdemo =preferences.systemroot().node(path); try{ prefsdemo.removenode(); }catch(exception e){ } } /*删除单个注册项*/ public static void delregbyname(string name,string path){ path=stringutil.nulltoempty(path); preferences prefsdemo =preferences.systemroot().node(path); try{ prefsdemo.remove(name); }catch(exception e){ } } /*导出注册表为xml文件*/ public static void outputreg(string regpath,string filepath){ regpath=stringutil.nulltoempty(regpath); preferences prefsdemo =preferences.systemroot().node(regpath); try { fileoutputstream fos = new fileoutputstream(filepath); prefsdemo.exportnode(fos); }catch (exception e) { system.err.println( "cannot export nodes: " + e); } } | | |
|