关闭

内部类序列化

标签: integerequalsvectorobjectstringclass
4812人阅读 评论(0) 收藏 举报
分类:

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

 

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();
        }
        
        
    }


0
1

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:126396次
    • 积分:1725
    • 等级:
    • 排名:千里之外
    • 原创:37篇
    • 转载:28篇
    • 译文:5篇
    • 评论:16条
    文章分类
    最新评论