内部类序列化

   只有静态内部类才能序列化

 

public void writeObject() {
        // readObject();
        ObjectOutputStream oos;
        try {
            oos = new ObjectOutputStream(this.openFileOutput("save.himi", MODE_PRIVATE));
            changeData();
            oos.writeObject(mapVector);
            oos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


 

public void readObject() {
        try {
            
                ObjectInputStream ois = new ObjectInputStream(
                        this.openFileInput("save.himi"));

                mapVector = (Vector) (ois.readObject());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


 

public static class MessageRememer implements Serializable{
        
        private static final long serialVersionUID= 1L;

        public MessageRememer(long accountId, long folderId, long messageId,int kind) {
            super();
            this.accountId = accountId;
            this.folderId = folderId;
            this.messageId = messageId;
            this.kind =kind;
        }
        private Long accountId;
        public Long getAccountId() {
            return accountId;
        }
        public void setAccountId(Long accountId) {
            this.accountId = accountId;
        }
        public Long getFolderId() {
            return folderId;
        }
        public void setFolderId(Long folderId) {
            this.folderId = folderId;
        }
        public Long getMessageId() {
            return messageId;
        }
        public void setMessageId(Long messageId) {
            this.messageId = messageId;
        }
        public Integer getKind() {
            return kind;
        }
        public void setKind(Integer kind) {
            this.kind = kind;
        }
        private Long folderId;
        private Long messageId;
        private Integer kind;
        
        @Override
        public boolean equals(Object o) {
            return super.equals(o);
        }
        @Override
        public int hashCode() {
            return super.hashCode();
        }
        @Override
        public String toString() {
            return super.toString();
        }
        
        
    }


阅读更多
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

内部类序列化

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭