我构造了一个JTree原本用的是这种方法:
 DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root", true);   
 fileTree = new JTree(root);
现在希望改变这种方法,将刚才构造好,通过下面方法存储的JTree读取出来:        theFrame.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e) {
                 try {
                     ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("t.txt"));
                     os.writeObject(fileTree);
                     os.close();
                 } catch (IOException ex) {
                     ex.printStackTrace();
                     }
                 if(JOptionPane.showConfirmDialog(null, "退出","提示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
                  System.exit(0);
                  }
            }
            }
        );现在我用的是这种方法读取:
        try {
          ObjectInputStream is = new ObjectInputStream(new FileInputStream("t.txt"));
             JTree fileTree = (JTree) is.readObject();
        }catch (Exception ex) {
            ex.printStackTrace();
        }
但是结果无论是序列化还是反序列化都报错啊。真心求教!!!!谢谢。。因为初学,希望各路牛人能将详细一点,最好给个小例子,或者告诉我程序的正确写法。。谢谢!!!!

解决方案 »

  1.   

    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: FileManagement.MyFileManagementjava.io.NotSerializableException: FileManagement.MyFileManagement

    java.lang.InternalError: incorrect component
    就是这个序列化和反序列化。。加这个之前都没有
      

  2.   

    FileManagement.MyFileManagement没有实现序列化接口?
      

  3.   

    我序列化的jTreeDefaultMutableTreeNode root = new DefaultMutableTreeNode("Root", true);fileTree = new JTree(root);try {
      ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("t.txt"));
      os.writeObject(fileTree);
      os.close();
      } catch (IOException ex) {
      ex.printStackTrace();
      }