序列化

作者: 萤火之森ss | 来源:发表于2017-08-24 17:12 被阅读4次
    package io;
    
    import com.car.service.model.Question;
    
    import java.io.*;
    
    /**
     * Created by Wangjianxin on 2017/8/24 0024.
     */
    public class Objectoutstrean {
    
        public static void main(String[] args) throws IOException{
    
            String f = "C:\\Users\\Administrator\\Desktop\\filetest\\ser.txt";
    
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
            Question question = new Question();
            question.setQuestitle("序列化");
            oos.writeObject(question);
            oos.flush();
            oos.close();
    
    
            
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
            try {
                Question question1 = (Question)ois.readObject();
                System.out.println(question1);
                ois.close();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    

    关键字tansient,修饰后代表不能被默认的序列化操作,但是我们可以手动的序列化操作
    对子类进行反序列操作时,如果父类没有实现序列化接口,那么父类的构造方法才会被调用

    相关文章

      网友评论

          本文标题:序列化

          本文链接:https://www.haomeiwen.com/subject/rhvedxtx.html