• 序列化的基本操作

  1.对象序列化,就是将Object转换成byte序列,反之叫对象的反序列化。

  2.序列化流(ObjectOutputStream),writeObject 方法用于将对象写入输出流中;

  反序列化流(ObjectInputStream),readObject 方法用于从输入流中读取对象。

  3.序列化接口(Serializeable)

  对象必须实现序列化接口,才能进行序列化,否则会出现异常。这个接口没有任何方法,只是一个标准。

package com.test.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; public class ObjectSerialzeTest {
/**
* 对象的序列化
* @param file
* @throws Exception
*/
public void ObjectOutput (String file) throws Exception {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
Student stu = new Student("002", "张四", 12);
oos.writeObject(stu);
oos.flush();
oos.close();
}
/**
* 对象的反序列化
* @param file
* @throws Exception
*/
public void ObjectInput(String file) throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
Student stu = (Student)ois.readObject();
System.out.println(stu.toString());
ois.close();
} public static void main(String[] args) throws Exception {
String file = "F:\\javaio\\obj.dat";
ObjectSerialzeTest ost = new ObjectSerialzeTest();
ost.ObjectOutput(file);
ost.ObjectInput(file);
}
}

最新文章

  1. 从源码看Azkaban作业流下发过程
  2. Cubieboard2裸机开发之(一)点亮板载LED
  3. 【MySQL】性能优化 之 延迟关联
  4. IDA 在string窗口中显示中文字符串
  5. Database事件研究
  6. Partition List -- LeetCode
  7. 第一个程序python.py
  8. Leetcode_252_Implement Stack using Queues
  9. Linux-网络基础
  10. 浅谈PageHelper插件分页实现原理及大数据量下SQL查询效率问题解决
  11. HDU 2544最短路 【dijkstra 链式前向星+优先队列优化】
  12. js dictionary
  13. OnApplicationFocus & OnApplicationPause &时间戳
  14. Java_文件夹拷贝
  15. phpstrom 激活
  16. 使用Jersey上传文件
  17. linux command useradd
  18. poj 2785 让和为0 暴力&二分
  19. IT行业简报 2014-2-8
  20. EINTR与ERESTARTSYS

热门文章

  1. grep练习
  2. laravel 运用
  3. 移远EC20的使用
  4. c# 如何得到一个字符的ASCII码
  5. vue相关问题在工作中的问题及ui组件及html样式搭建相关网站下载资源
  6. logback.xml文件配置(按时间、文件大小和log名称生成日志)
  7. Python爬虫抓取某音乐网站MP3(下载歌曲、存入Sqlite)
  8. 实体类的状态与Hibernate缓存
  9. React.js 小书 Lesson21 - ref 和 React.js 中的 DOM 操作
  10. 利用git工具命令简单的从github上拷贝和上传代码