Java的反序列化

Demo源码:
https://gitlab.com/caiqiqi/Java_Serialization

为什么要进行Java对象的序列化

参考:
http://www.hollischuang.com/archives/1140
Java平台允许我们在内存中创建可复用的Java对象,但一般情况下,只有当JVM处于运行时,这些对象才可能存在,即,这些对象的生命周期不会比JVM的生命周期更长。但在现实应用中,就可能要求在JVM停止运行之后能够保存(持久化)指定的对象,并在将来重新读取被保存的对象。Java对象序列化就能够帮助我们实现该功能。

➜  ~/GitProjects/Java_Serialization  javac *.java
➜  ~/GitProjects/Java_Serialization  java Serialization
➜  ~/GitProjects/Java_Serialization  ls                                                        [1:56:37]
Deserialization.class Person.bin            Person.java           Serialization.java
Deserialization.java  Person.class          Serialization.class
➜  ~/GitProjects/Java_Serialization  file Person.bin                                           [1:56:38]
Person.bin: Java serialization data, version 5
➜  ~/GitProjects/Java_Serialization  file Person.class                                         [1:56:44]
Person.class: compiled Java class data, version 51.0 (Java 1.7)
➜  ~/GitProjects/Java_Serialization  java Deserialization                                      [1:56:51]
Person@454322ba
➜  ~/GitProjects/Java_Serialization  javac Deserialization.java                                [1:58:08]
➜  ~/GitProjects/Java_Serialization  java Deserialization                                      [1:58:13]
Person@31955dd4
➜  ~/GitProjects/Java_Serialization  vi Deserialization.java                                   [1:58:17]
➜  ~/GitProjects/Java_Serialization  javac Deserialization.java                                [1:59:28]
➜  ~/GitProjects/Java_Serialization  java Deserialization                                      [1:59:32]
Name:       caiqiqiBirthDate:       Thu Jan 01 08:00:04 CST 1970
➜  ~/GitProjects/Java_Serialization  vi Deserialization.java                                   [1:59:35]
➜  ~/GitProjects/Java_Serialization  javac Deserialization.java                                [2:00:08]
➜  ~/GitProjects/Java_Serialization  java Deserialization                                      [2:00:15]
Name:       caiqiqi
BirthDate:      Thu Jan 01 08:00:04 CST 1970
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值