首页 > 其他 > 详细

对象反序列化流ObjectInputStream

时间:2020-04-24 17:52:46      阅读:72      评论:0      收藏:0      [点我收藏+]
ObjectInputStream反序列化先前使用ObjectOutputStream编写的原始数据和对象。
构造方法:ObjectInputStream(InputStream in)创建从指定的InputStream读取的ObjectInputStream。 
readObject()从ObjectInputStream读取一个对象。 
public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("myFile\\oos.txt"));

        Object obj = ois.readObject();

        //向下转型
        Student s = (Student)obj;

        System.out.println(s.getName()+","+s.getAge());
     ois.close(); }

运行结果:

技术分享图片

通过对象反序列化流就可以反序列化先前使用对象序列化编写的原始数据和对象。

技术分享图片

对象反序列化流ObjectInputStream

原文:https://www.cnblogs.com/pxy-1999/p/12768797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!