1 / 11
文档名称:

对象序列化和反序列化.docx

格式:docx   大小:38KB   页数:11页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

对象序列化和反序列化.docx

上传人:iris028 2022/6/19 文件大小:38 KB

下载得到文件列表

对象序列化和反序列化.docx

文档介绍

文档介绍:Java基础学****总结——Java对象的序列化和反序列化
一、序列化和反序列化的概念
  把对象转换为字节序列的过程称为对象的序列化。
  把字节序列恢复为对象的过程称为对象的反序列化。
  对象的序列化主要有两种用途:
  1) n类对象
1 import ;
2 import ;
3 import ;
4 import ;
5 import ;
6 import ;
7 import ;
8 import ;
9
10 /**
11 * <p>ClassName: TestObjSerializeAndDeserialize<p>
12 * <p>Description: 测试对象的序列化和反序列<p>
13 * ***@author xudp
14 * ***@version V
15 * ***@createTime 2014-6-9 下午03:17:25
16 */
17 public class TestObjSerializeAndDeserialize {
18
19 public static void main(String[] args) throws Exception {
20 SerializePerson();//序列化Person对象
21 Person p = DeserializePerson();//反序列Perons对象
22 (("name={0},age={1},sex={2}",
23 (), (), ()));
24 }
25
26 /**
27 * MethodName: SerializePerson
28 * Description: 序列化Person对象
29 * ***@author xudp
30 * ***@throws FileNotFoundException
31 * ***@throws IOException
32 */
33 private static void SerializePerson() throws FileNotFoundException,
34 IOException {
35 Person person = new Person();
36 ("gacl");
37 (25);
38 ("男");
39 // ObjectOutputStream 对象输出流,,完成对Person对象的序列化操作
40 ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(
41 new File("E:/")));
42 (person);
43 ("Person对象序列化成功!");
44 ();
45 }
46
47 /**
48 * MethodName: DeserializePerson
49 * Description: 反序列Perons对象
50 * ***@author xudp
51 * ***@return
52 * ***@throws Exception
53 * ***@throws IOException