惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
U
Unit 42
Y
Y Combinator Blog
I
InfoQ
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
量子位
Microsoft Security Blog
Microsoft Security Blog
B
Blog
The Cloudflare Blog
F
Fortinet All Blogs
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
C
Check Point Blog
S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
T
Tailwind CSS Blog

博客园 - 淡无心

Git 常用操作命令手册 Idea快捷键 Java_core复习 gitblit重置管理员密码【gitblit】 使用命令创建git仓库 Windows平台下搭建自己的Git服务器【gitblit】 python笔记 代码整洁之道 Vue学习02 Vue学习01 linux 服务器挂在目录 java内部编码 用base64Encoder进行编码 和base64Decoder解码 HttpServletResponse类 配置Tomcat服务器数据连接池 SVN修改地址 Linux初始root密码设置 plsql的使用,本地只装一个客户端。 [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
序列化和反序列化
淡无心 · 2016-07-15 · via 博客园 - 淡无心

序列化和反序列化

1.序列化
//创建一个用于接收被序列化的对象实例字节流ByteArrayOutputStream对象 ByteArrayOutputStream classBytes = new ByteArrayOutputStream(); //创建一个用于向流中写入对象的ObjectOutputStream对象 ObjectOutputStream oos = new ObjectOutputStream(classBytes); oos.writeObject(new MyCookie()); oos.close(); //关闭ObjectOutputStream对象

 2.反序列化

         ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(classBytes));
	    //得到MyCookie兑现实例
       	MyCookie myCookie = (MyCookie) ois.readObject();     

posted @ 2016-07-15 13:50  淡无心  阅读(189)  评论(0)    收藏  举报