package JBJADV003;
import java.io.*;
public class ReadTeacherObj {

/**
* @param args
*/
public static void main(String[] args) throws IOException, ClassNotFoundException {
ObjectInputStream ois=null;
try{
//创建ObjectOutputStream输出流
ois=new ObjectInputStream(new FileInputStream("c:\\myDoc\\tea.txt"));
//反序列化,强转类型
Student stu=(Student)ois.readObject();
Teacher teacherWang=(Teacher)ois.readObject();
Teacher teacherLi=(Teacher)ois.readObject();
//输出生成后对象信息
System.out.println("学生姓名为:"+stu.getName());
System.out.println("第一个老师姓名为:"+teacherWang.getName());
System.out.println("第二个老师姓名为:"+teacherLi.getName());
//判断对象指向是否相同
if(teacherWang.getstu()==stu && teacherLi.getstu()==stu){
System.out.println("对象相同。");
}else{
System.out.println("对象不同。");
}

}catch(IOException ex){
ex.printStackTrace();
}finally{
if(ois!=null){
ois.close();
}
}

}

}

05-04 02:34