package zhang; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class TEST { public static void write() throws Exception, IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E://Data.txt")); Student s = new Student("zhang",20,"121"); s.schoolName="BJ"; oos.writeObject(s); oos.close(); } public static void read() throws Exception, IOException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:\\Data.txt")); Student s = (Student)ois.readObject(); ois.close(); System.out.println(s); } public static void main(String[] args) throws IOException, Exception { write(); read(); } }