Using the Java.util.prefs package to operate the Windows registry
Java Operations Windows Registry, primary API
Main interface
Interface |
Description |
Nodechangelistener |
The listener used to receive the preference node Change event. |
Preferencechangelistener |
The listener used to receive the preference node Change event. |
Preferencesfactory |
The factory object that generates the Preferences object. |
Main class
class |
Description |
Abstractpreferences |
This class provides a backbone implementation of the preferences class, which greatly simplifies the task of implementing this class. |
Nodechangeevent |
An event emitted by the preferences node that indicates that the node's child nodes have been added or removed. |
Preferencechangeevent |
An event emitted by the preference node that indicates that the first option has been added or removed, or that the value of the preference item has been changed. |
Preferences |
The node in the hierarchy collection of the preference data. |
Major exceptions
Exception |
Description |
Backingstoreexception |
Throwing this exception indicates that the preferences operation cannot be completed because of an internal storage failure or inability to contact internal storage. Listener. |
Invalidpreferencesformatexception |
Throwing this exception indicates that, according to the preferences specification, the input does not conform to the correct XML document type of the preferences collection, so the operation cannot be completed. |
Sample code
ImportJava.util.prefs.BackingStoreException;ImportJava.util.prefs.Preferences; Public class Test { Public Static void Main(string[] args) {Preferences pre=preferences.systemnodeforpackage (test.class); Pre.put ("UserName","******"); Pre.putint ("Age", -);Try{Pre.flush (); }Catch(Backingstoreexception e) {E.printstacktrace (); } Preferences Now=preferences.systemnodeforpackage (Test.class); System.out.println (Now.get ("UserName","is empty")); System.out.println (Now.getint ("Age",0)); }}
Other
if Systemnodeforpackage is selected, it is saved in [Hkey_local_machine\software\javasoft\prefs]
If Usernodeforpackage is selected, it is saved in [Hkey_current_user\software\javasoft\prefs]
There are a number of limitations if you want to add a program to your registry's autorun keys. Or do you want to use Java to call batch processing.
Using the Java.util.prefs package to operate the Windows registry