书上没写,不大懂,谢谢。

解决方案 »

  1.   

    [code = java]
    public class Blips {  
      
        /** 
         * @param args 
         * @throws IOException  
         * @throws IOException 
         * @throws ClassNotFoundException  
         * @throws FileNotFoundException 
         * @throws ClassNotFoundException  
         */  
        public static void main(String[] args) throws IOException, ClassNotFoundException  {  
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(  
                        new FileOutputStream("c:/Blips.txt"));  
                objectOutputStream.writeObject(new Blip1());  
                objectOutputStream.writeObject(new Blip2());  
                objectOutputStream.close();  
                System.out.println("1111111111111111111");  
                  
                ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("c:/Blips.txt"));  
                objectInputStream.readObject();  
                objectInputStream.readObject();  
                objectInputStream.close();  
                System.out.println("222222222222222222222");  
        }  
      
    }  
    [/code]
      
    class Blip1 implements Externalizable {  
      
        public Blip1() {  
            System.out.println("Blip1.Blip1()");  
        }  
      
        @Override  
        public void readExternal(ObjectInput in) throws IOException,  
                ClassNotFoundException {  
            System.out.println("Blip1.readExternal()");  
        }  
      
        @Override  
        public void writeExternal(ObjectOutput out) throws IOException {  
            System.out.println("Blip1.writeExternal()");  
        }  
      
    }  
      
    class Blip2 implements Externalizable {  
      
        Blip2() {  
            System.out.println("Blip2.Blip2()");  
        }  
      
        @Override  
        public void readExternal(ObjectInput in) throws IOException,  
                ClassNotFoundException {  
            System.out.println("Blip2.readExternal()");  
        }  
      
        @Override  
        public void writeExternal(ObjectOutput out) throws IOException {  
            System.out.println("Blip2.writeExternal()");  
        }  
      
    }