import java.io.*; 
 public class Forest implements Serializable {      private Tree tree = new Tree(); 
        public static void main(String [] args) { 
            Forest f = new Forest(); 
               try {                       FileOutputStream fs = new FileOutputStream("Forest.ser"); 
                      ObjectOutputStream os = new ObjectOutputStream(fs); 
                      os.writeObject(f); 
                      os.close(); 
               } catch (Exception ex) { ex.printStackTrace(); } 
        }
        class Tree {}
 }
       

解决方案 »

  1.   

    难道就是Forest.ser的路径没有设置,才抛出异常?
      

  2.   


    public class Forest implements Serializable{
         private Tree tree = new Tree(); 
         public static void main(String [] args) { 
          Forest f = new Forest (); 
               try {                    FileOutputStream fs = new FileOutputStream("D:\\Forest.ser"); 
                       ObjectOutputStream os = new ObjectOutputStream(fs); 
                       os.writeObject(f); 
                       os.close(); 
               } catch (Exception ex) { ex.printStackTrace(); } 
         } 
         class Tree implements Serializable{} }