import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable; class Employee {
private String name; Employee(String name) {
this.name = name;
} @Override
public String toString() {
return name;
}
} class SerEmployee extends Employee implements Serializable {
SerEmployee(String name) {
super(name);
}
} public class SerializationDemo {
public static void main(String[] args) {
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
try {
oos = new ObjectOutputStream(new FileOutputStream("employee.dat"));
SerEmployee se = new SerEmployee("John Doe");
System.out.println(se);
oos.writeObject(se);
oos.close();
oos = null;
System.out.println("se object written to file");
ois = new ObjectInputStream(new FileInputStream("employee.dat"));
se = (SerEmployee) ois.readObject();
System.out.println("se object read from file");
System.out.println(se);
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (oos != null)
try {
oos.close();
} catch (IOException ioe) {
assert false; // shouldn't happen in this context
}
if (ois != null)
try {
ois.close();
} catch (IOException ioe) {
assert false; // shouldn't happen in this context
}
}
}
}

java ObjectOutputStream的更多相关文章

  1. [Android] Java Basic : preview

    基础教学:lecture, video, lecturer: Matt Stoker Java教学:http://www.runoob.com/java/java-intro.html[菜鸟教程,非常 ...

  2. JAVA学习笔记及知识积累

    为什么说Java具有跨平台特性? 我们知道计算机只认识1,0两种电平的信号,所有信息或者计算指令最终都编码成16进制的机器码,这些机器码作为程序保存于计算机的内存中,由CPU去单个取指令执行直到程序执 ...

  3. java流(二)

    目录 1 ObjectOutputStream/ObjectInputStream的使用 2 序列化 3 具体序列化的过程 4 Externalizable的简易介绍 实现序列化的Person类 /* ...

  4. Hadoop基础-Apache Avro串行化的与反串行化

    Hadoop基础-Apache Avro串行化的与反串行化 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Apache Avro简介 1>.Apache Avro的来源 ...

  5. 一分钟了解spark的调优

    Tuning Spark 数据序列化 内存调优 内存管理概述 确定内存消耗 调整数据结构 序列化 RDD 存储 垃圾收集调整 其他注意事项 并行度水平 减少任务的内存使用 广播大的变量 数据本地化 概 ...

  6. spark系列-4、spark序列化方案、GC对spark性能的影响

    一.spark的序列化 1.1.官网解释 http://spark.apache.org/docs/2.1.1/tuning.html#data-serialization 序列化在任何分布式应用程序 ...

  7. Programiz 中文系列教程·翻译完成

    原文:Programiz 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. 在线阅读 ApacheCN 学习资源 目录 Programiz C ...

  8. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  9. (JAVA)从零开始之--对象输入输出流ObjectInputStream、ObjectOutputStream(对象序列化与反序列化)

    对象的输入输出流 : 主要的作用是用于写入对象信息与读取对象信息. 对象信息一旦写到文件上那么对象的信息就可以做到持久化了 对象的输出流: ObjectOutputStream 对象的输入流:  Ob ...

随机推荐

  1. GridView块布局

    <GridView android:id="@+id/gridview" android:layout_width="match_parent" andr ...

  2. node基础 --概念

    非阻塞IO: node.js使用了事件轮询 setTimeout是非阻塞的: 对于像http,net等原生模块中IO部分也采用了事件轮询,其本质是: 当node接受到浏览器的http请求时,底层的TC ...

  3. Xamarin iOS编写第一个应用程序创建工程

    Xamarin iOS编写第一个应用程序创建工程 在Xcode以及Xamarin安装好后,就可以在Xamarin Studio中编写程序了.本节将主要讲解在Xamarin Studio中如何进行工程的 ...

  4. Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  5. struts2总结四:Action与Form表单的交互

    struts2 Action获取表单数据的方式有三种:1.通过属性驱动的方式.2.模型驱动方式.3.使用多个model对象的属性. 1.通过属性驱动式 首先在jsp里面编写form表单的代码如下: & ...

  6. HDU 4003 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4003 题目大意:有K个机器人,走完树上的全部路径,每条路径有个消费.对于一个点,机器人可以出去再回来 ...

  7. POJ 1734 Sightseeing trip(无向图最小环+输出路径)

    题目链接 #include <cstdio> #include <string> #include <cstring> #include <queue> ...

  8. POJ 3270 Cow Sorting(置换群)

    题目链接 很早之前就看过这题,思路题把,确实挺难想的,黑书248页有讲解. #include <cstdio> #include <cstring> #include < ...

  9. BZOJ3339 Rmq Problem

    [bzoj3339]Rmq Problem Description Input Output Sample Input 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 Sa ...

  10. Get the log from android device

    Theme: How to get the log from device ?  Detail:  Get the log from device, and write to the local fi ...