代码

package xcdq;

import java.io.*;

public class demo01 {

public static void main(String[] args)throws IOException, ClassCastException{

User u1 =new User("阿伟",18);

        System.out.println(u1);

        ObjectInputStream oos =new ObjectInputStream(new FileInputStream("tempfile"));

        oos.writeObject(u1);

        ObjectInputStream ois =new ObjectInputStream(new FileInputStream("tempfile"));

        User u2 = (User) ois.readObject();

        System.out.println(u2);

    }

}

你可能感兴趣的:(代码)