The java.util.prefs
package provides a way for applications to store and retrieve user and system preferences and data configuration. These preference data will be stored persistently in an implementation-dependent backing stored. For example in Windows operating system in will stored in Windows registry.
To write and read these data we use the java.util.prefs.Preferences
class. The following example will show you how to read and write to the HKCU
(HKEY_CURRENT_USER
) in the registry.
package org.kodejava.util.prefs;
import java.util.prefs.Preferences;
public class RegistryDemo {
public static final String PREF_KEY = "kodejava";
public static void main(String[] args) {
// Write Preferences information to HKCU (HKEY_CURRENT_USER),
// HKCU\SOFTWARE\JavaSoft\Prefs
Preferences userPref = Preferences.userRoot();
userPref.put(PREF_KEY, "https://kodejava.org");
// Below we read back the value we've written in the code above.
System.out.println("Preferences = "
+ userPref.get(PREF_KEY, PREF_KEY + " was not found."));
}
}
Latest posts by Wayan (see all)
- How do I create a servlet filter to make secure cookies? - April 18, 2024
- How do I configure secure cookies using web.xml? - April 18, 2024
- How do I create a table with multiple header in iText 8? - March 16, 2024