Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4397109

java.util.prefs.Preferences exportNode(java.io.OutputStream os)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • None
    • x86
    • windows_nt

      // java.util.prefs.Preferences exportNode(java.io.OutputStream os)

      //key and value pairs are not written in the output file user01.pfs file
      //program and output are as shown below.


      import java.util.prefs.*;
      import java.util.*;
      import java.io.*;

      public class ExportNodeWrite {
        
          public static void main(String[] args) {
              try{
                 Preferences userRoot = Preferences.userRoot();
                 
                 Preferences N1 = userRoot.node("N1");
                 N1.removeNode();
                 N1 = userRoot.node("N1");
                 N1.put("k1","v1");
                 Preferences N2 = N1.node("N2");
                 N2.put("k2","v2");
                 userRoot.flush();

                 
                 File systemFile = new File("user01.pfs");
                 FileOutputStream fos = new FileOutputStream(systemFile);
                 N2.exportNode(fos);
                 fos.close();
                 System.out.println("user01.pfs output");
                 System.out.println();
                 RandomAccessFile raf = new RandomAccessFile("user01.pfs","r");
                 String line = null;
                 while ( (line = raf.readLine()) !=null) {
                    System.out.println(line);
                 }
               } catch(Exception e) {
                  System.out.println("exception thrown " + e);
               }
               
          
         }
       
      }

      //////////////output


      I:\merlinTest\preferences\bug\exportNode>java ExportNodeWrite
      user01.pfs output

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd&#39;>

      <preferences>
        <root type="user">
          <node name="N1">
            <node name="N2" />
          </node>
        </root>
      </preferences>

            jjb Josh Bloch (Inactive)
            spandeorcl Shantaram Pande (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: