package JBJADV003;
import java.io.*;
public class WriteTeacherObj {
/**
* @param args
*/
public static void main(String[] args)throws FileNotFoundException, IOException {
ObjectOutputStream oos=null;
try{
//创建ObjectOutputStream输出流
oos=new ObjectOutputStream(new FileOutputStream("c:\\myDoc\\tea.txt"));
Student stuZhang=new Student("韩冰",22,"女","123456");
Teacher teacherWang=new Teacher("王老师",stuZhang);
Teacher teacherLi=new Teacher("李老师",stuZhang);
//对象序列化,写入输出流
oos.writeObject(stuZhang);
oos.writeObject(teacherWang);
oos.writeObject(teacherLi);
}catch(IOException ex){
ex.printStackTrace();
}finally{
if(oos!=null){
oos.close();
}
}
}
}
原文:http://www.cnblogs.com/JesseCary/p/4504817.html