Using the Java.util.prefs package to operate the Windows registry

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.