Saving and Retrieving a Preference Value - Java Native OS

Java examples for Native OS:Preference

Description

Saving and Retrieving a Preference Value

Demo Code

import java.util.prefs.Preferences;

public class Main {

  public void main(String[] argv) {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);

    final String PREF_NAME = "name_of_preference";

    // Set the value of the preference
    String newValue = "a string";
    prefs.put(PREF_NAME, newValue);//from   w  w w. ja va  2s  . c o  m

    // Get the value of the preference;
    String defaultValue = "default string";
    String propertyValue = prefs.get(PREF_NAME, defaultValue); // "a string"
  }
}

Related Tutorials