⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e420. exporting the preferences in a subtree of preference nodes.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
This example demonstrates how to export the preferences of nodes in a subtree of preference nodes to a file. The export values can be imported using Preferences.importPreferences() (see e418 Importing Preferences). The format of the exported data is XML. 
For every node in the exported subtree, the path of the node and the preferences in that node are exported. When the data is later imported, the preferences are added to nodes with exactly the same paths. 

    // Retrieve the user preference node for the package java.lang
    Preferences prefs = Preferences.userNodeForPackage(String.class);
    
    // Save some values
    prefs.put("myString", "a string");        // String
    prefs.putBoolean("myBoolean", true);      // boolean
    prefs.putInt("myInt", 123);               // int
    prefs.putLong("myLong", 123L);            // long
    
    // Save some values in the parent node
    prefs = prefs.parent();
    prefs.putFloat("myFloat", 12.3F);         // float
    prefs.putDouble("myDouble", 12.3);        // double
    byte[] bytes = new byte[10];
    prefs.putByteArray("myByteArray", bytes); // byte[]
    
    try {
        prefs.exportSubtree(new FileOutputStream("output.xml"));
    } catch (IOException e) {
    } catch (BackingStoreException e) {
    }

The code above generates the following XML data: 
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
    
    <preferences EXTERNAL_XML_VERSION="1.0">
      <root type="user">
        <map />
        <node name="java">
          <map>
            <entry key="myFloat" value="12.3" />
            <entry key="myDouble" value="12.3" />
            <entry key="myByteArray" value="AAAAAAAAAAAAAA==" />
          </map>
          <node name="lang">
            <map>
              <entry key="myString" value="a string" />
              <entry key="myBoolean" value="true" />
              <entry key="myInt" value="123" />
              <entry key="myLong" value="123" />
            </map>
          </node>
        </node>
      </root>
    </preferences>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -