• 特殊操作流之对象序列化流和对象反序列化流


     

    package com.io.liushuaishuai;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    
    public class ObjectOutputStreamDemo01 {
        public static void main(String[] args) throws IOException {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("myIOstream\copy02.java"));
            Student s1 = new Student("林青霞", 99, 50, 80);
            oos.writeObject(s1);
            /*
            NotSerializableException:抛出一个实例需要一个Serializable接口。
            序列化运行时或实例的类可能会抛出此异常。 参数应该是类的名称。
     Serializable类的序列化由实现java.io.Serializable接口的类启用。
    不实现此接口的类将不会使任何状态序列化或反序列化。
    可序列化类的所有子类型都是可序列化的。
     序列化接口没有方法或字段,仅用于标识可串行化的语义
    
             */
    
    
            oos.close();
    
        }
    }
    

     

    package com.io.liushuaishuai;
    
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    
    public class ObjectInputStreamDemo {
        public static void main(String[] args) throws IOException, ClassNotFoundException {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("myIOstream\copy02.java"));
            Student s = (Student) ois.readObject();
            System.out.println(s.getName() + " " + s.getChinese() + " " + s.getMath() + " " + s.getEnglish());

        ois.close(); } }
  • 相关阅读:
    python 适合的才是最好的
    [转]linux 同步IO: sync、fsync与fdatasync
    Java Metrics系统性能监控工具
    [转]mysql共享锁和排它锁
    基于空间数据库MongoDB实现全国电影票预定系统
    sharing-jdbc分库分表规则
    乐观锁更新失败处理小坑
    通过MessageFormat进行字符格式拼接,比String.format跟方便
    通过jvisualvm监控fullgc
    防止重复提交
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11431257.html
Copyright © 2020-2023  润新知