标签:txt ... 序列 dex pack ati otf etag 序列化
Java序列化与反序列化
1 package com.study.file; 2 3 import java.io.FileInputStream; 4 import java.io.FileNotFoundException; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.ObjectInputStream; 9 import java.io.ObjectOutputStream; 10 import java.io.OutputStream; 11 12 import com.study.bean.Emp; 13 14 /** 15 * Java 序列化与反序列化 16 * @ClassName: SerializableDemo 17 * @author BlueLake 18 * @date 2016年9月10日 下午5:42:09 19 */ 20 public class SerializableDemo { 21 22 public static void main(String[] args) throws IOException, ClassNotFoundException { 23 Emp emp = new Emp(); 24 emp.setAge("18"); 25 emp.setUname("魔女"); 26 /* 27 * 序列化:把对象写到文件 28 * 29 */ 30 OutputStream os = new FileOutputStream("F:/Test/inter.txt"); 31 ObjectOutputStream oos = new ObjectOutputStream(os); 32 oos.writeObject(emp); 33 /* 34 * 反序列化:把文件读出成对象 35 * 36 */ 37 InputStream is = new FileInputStream("F:/Test/inter.txt"); 38 ObjectInputStream ois = new ObjectInputStream(is); 39 Object obj = ois.readObject(); 40 if(obj instanceof Emp){ 41 Emp em = (Emp)obj; 42 System.out.println(em.getAge()+"..."+em.getUname()); 43 } 44 45 oos.close(); 46 ois.close(); 47 } 48 }
标签:txt ... 序列 dex pack ati otf etag 序列化
原文地址:http://www.cnblogs.com/tashaxing/p/7501666.html