Java Preference backingStoreAvailable(Preferences prefs)

Here you can find the source of backingStoreAvailable(Preferences prefs)

Description

Test whether preference can be written to disk from: http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html#prefs-usage-backingstore

License

BSD License

Declaration

public static boolean backingStoreAvailable(Preferences prefs) 

Method Source Code

//package com.java2s;
// LICENSE:      This file is distributed under the BSD license.

import java.util.prefs.Preferences;
import java.util.prefs.BackingStoreException;

public class Main {
    private static final String BACKING_STORE_AVAIL = "BackingStoreAvail";

    /**//from   ww w. ja v  a2 s  .c om
     * Test whether preference can be written to disk
     * from:
     * http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html#prefs-usage-backingstore
     */
    public static boolean backingStoreAvailable(Preferences prefs) {
        try {
            boolean oldValue = prefs.getBoolean(BACKING_STORE_AVAIL, false);
            prefs.putBoolean(BACKING_STORE_AVAIL, !oldValue);
            prefs.flush();
        } catch (BackingStoreException e) {
            return false;
        }
        return true;
    }
}

Related

  1. cambiarIdioma(String lang, String country)
  2. classFor(Object obj)
  3. clearPreference(Object context)
  4. count(Preferences preferences, String preferenceName)