import java.io.*;
import java.util.*;

class T implements Serializable {
	private String str = "abc";
	private Date date = new Date();
	private int k = 10;
	private boolean bool = true;
	
	static String sta ="static member";
	transient String trans = "transient member";

	public void print(){
		System.out.println(str);
		System.out.println(date);
		System.out.println(k);
		System.out.println(bool);
		System.out.println(sta);
		System.out.println(trans);
	}
}

public class ObjectStreamTest {
	public static void main(String[] args) throws Exception {
		ObjectOutputStream objout = null;
		ObjectInputStream objin = null;

		try{
			objout=new ObjectOutputStream(
					new FileOutputStream("objfile")
					);//创建对象流。
			objout.writeObject(new T());//写入一个类对象。
			objout.flush();
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			if (objout != null){
				objout.close();
			}
		}
		try{
			objout.close();

			objin = new ObjectInputStream(
					new FileInputStream("objfile"));//创建对象流。
			T t =(T)objin.readObject();
			t.print();
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			if(objin !=null){
				objin.close();
			}
		}
	}
}
