The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.prefs  [18 examples] > Importing and Exporting  [3 examples]

e418. Importing Preferences

Preferences can be exported using Preferences.exportNode() (see e419 Exporting the Preferences in a Preference Node) and Preferences.exportSubtree() (see e420 Exporting the Preferences in a Subtree of Preference Nodes). This exported data can be imported using Preferences.importPreferences().

Each preference in exported data contains the path of the node that held the preference. When the exported preference is later imported, it is added to the node with the same path.

This example demonstrates how to import a file of exported preference data.

    
    // Create an input stream on a file
    InputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream("output.xml"));
    } catch (FileNotFoundException e) {
    }
    
    // Import preference data
    try {
        Preferences.importPreferences(is);
    } catch (InvalidPreferencesFormatException e) {
    } catch (IOException e) {
    }

 Related Examples
e419. Exporting the Preferences in a Preference Node
e420. Exporting the Preferences in a Subtree of Preference Nodes

See also: Events    Nodes   


© 2002 Addison-Wesley.