package J20250728;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo03_ObjectInputStream
 * @description ObjectInputStream 对象字节输入流---对象反序列化
 * @create 2025/7/28
 */
public class Demo03_ObjectInputStream {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //基础流--文件输出流
        FileInputStream fos=new FileInputStream("D:/保存对象.txt");
        //处理流-对象序列化
        ObjectInputStream ois=new ObjectInputStream(fos);
        //读取一个对象，这个对象的类型是object
        Object o = ois.readObject();
        Person p=null;
        //我们需要强转为自己要的类型
        if (o instanceof Person){
            p=(Person) o;
        }
        System.out.println(p.getId());
        System.out.println(p.getName());
        System.out.println(p.getAge());

        ois.close();
        fos.close();
    }
}
