Mega Code Archive

 
Categories / Java / Development Class
 

Retrieve the preference node using a Class object and saves and retrieves a preference in the node

import java.util.prefs.Preferences; public class Main {   public static void main(String[] argv) throws Exception {     Preferences prefs = Preferences.userNodeForPackage(Main.class);     final String PREF_NAME = "your_preference";     String newValue = "a string";     prefs.put(PREF_NAME, newValue);     String defaultValue = "default string";     String propertyValue = prefs.get(PREF_NAME, defaultValue); // "a string"   } }