package JBJADV003;
import java.io.*;
public class readSerializableObj {
public static void main(String[] args) throws IOException, ClassNotFoundException {
ObjectInputStream ois=null;
try{
//创建ObjectOutputStream输出流
ois=new ObjectInputStream(new FileInputStream("c:\\myDoc\\stu.txt"));
//反序列化,强转类型
Student stu=(Student)ois.readObject();
//输出生成后对象信息
System.out.println("姓名为:"+stu.getName());
System.out.println("年龄为:"+stu.getAge());
System.out.println("性别为:"+stu.getGender());
System.out.println("密码为:"+stu.getpassword());
}catch(IOException ex){
ex.printStackTrace();
}finally{
if(ois!=null){
ois.close();
}
}
}
}

05-06 03:44