对象流笔记整理

来源:互联网 发布:电脑管家硬件数据 编辑:程序博客网 时间:2024/06/06 23:36

对象流 Object流

ObjectInputStream

ObjectOutputStream


用ObjectOutputStream写到文件中的数据

必须通过ObjectInputStream 读出

而且  读的顺序  必须和 写的顺序一致


通过Object 流可以对对象直接进行读写操作


如果读到文件末尾  继续读写   会出现 EOFException End Of File Exception


Serializable

可序列化(可串行化)


如果想使用readObject  或者 writeObject 方法  读 写 一个 对象

那么该对象 对应的 类  一定要  可被序列化!

实现Serializable接口

seriaVersionUID  值  读 和 写 保持一致


-------------------------------------------------------

问题:

class A

class B extends A implements Serializable 


B b = new B();

writeObject(b);



class A implements Serializable 

class B extends A 


B b = new B();

writeObject(b);



class A 

class B implements Serializable{


private A a;


}

B b = new B();

writeObject(b);

1 0