public final void writeObject(Object x) throws IOException
public final Object readObject() throws IOException,
ClassNotFoundException
public class Employee implements java.io.Serializable
{
public String name;
public String address;
public transient int SSN;
public int number;
public void mailCheck()
{
System.out.println("Mailing a check to " + name
+ " " + address);
}
}
import java.io.*;

public class SerializeDemo
{
public static void main(String [] args)
{
Employee e = new Employee();
e.name = "Reyan Ali";
e.address = "Phokka Kuan, Ambehta Peer";
e.SSN = 11122333;
e.number = 101;
try
{
FileOutputStream fileOut =
new FileOutputStream("/tmp/employee.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in /tmp/employee.ser");
}catch(IOException i)
{
i.printStackTrace();
}
}
}
import java.io.*;

public class DeserializeDemo
{
public static void main(String [] args)
{
Employee e = null;
try
{
FileInputStream fileIn = new FileInputStream("/tmp/employee.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (Employee) in.readObject();
in.close();
fileIn.close();
}catch(IOException i)
{
i.printStackTrace();
return;
}catch(ClassNotFoundException c)
{
System.out.println("Employee class not found");
c.printStackTrace();
return;
}
System.out.println("Deserialized Employee...");
System.out.println("Name: " + e.name);
System.out.println("Address: " + e.address);
System.out.println("SSN: " + e.SSN);
System.out.println("Number: " + e.number);
}
}

最新文章

  1. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
  2. tuple元组(C++11及以后,如C++14)
  3. Spring MVC 中文乱码的解决
  4. hdu 4893 Wow! Such Sequence!
  5. PHP 5 数据类型
  6. HTML5 Web缓存&运用程序缓存&cookie,session
  7. 苹果系统css样式变化
  8. 错误问题:OpenGL version to old,GLViewinitWithRect(const stdbasic_stringchar,stdchar_traitschar,stdalloca
  9. [Swift]LeetCode349. 两个数组的交集 | Intersection of Two Arrays
  10. 最接近的三数之和(给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数, 使得它们的和与 target 最接近。返回这三个数的和)
  11. C#指定长度截取字符串 并进行拼接。
  12. jmeter创建数据库测试计划
  13. ADC分类及参数
  14. Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd'
  15. 高斯-克吕格投影与UTM投影
  16. leetcode55—Jump Game
  17. Nginx + uWSGI 部署Django 项目,并实现负载均衡
  18. OpenERP7.0中日期的问题
  19. SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询
  20. 18.async函数

热门文章

  1. APP中H5页面调试神器
  2. 51nod 1438:方阵与完全平方数
  3. POJ 1062:昂贵的聘礼
  4. Java集合--list接口
  5. 干货 | 用Serverless快速在APP中构建调研问卷
  6. dockerfile---apt-get install vim 时 Unable to locate package vim
  7. 同行评审|keywords
  8. [CF百场计划]Codeforces Round #617 (Div. 3)
  9. shell 实现war包的配置更新和自动发布
  10. 利用Matlab神经网络计算包预测近四天除湖北外新增确诊人数:拐点已现