ObjectInputStream对象输入流
- 读取(反序列化)的顺序需要和你保存数据(序列化)的顺序一致
public class ObjectInputStream01 {
public static void main(String[] args) throws IOException, ClassNotFoundException {
String filePath = "D:\\data.dat";
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filePath));
System.out.println(ois.readInt());
System.out.println(ois.readBoolean());
System.out.println(ois.readChar());
System.out.println(ois.readDouble());
System.out.println(ois.readUTF());
Object dog = ois.readObject();
System.out.println("运行类型:"+dog.getClass());
System.out.println("dog信息:"+dog);
ois.close();
}
}