オブジェクトに対する入出力

import java.io.*;

public class Test {
	public static void main(String args[]) throws IOException, ClassNotFoundException
	{
		Member m1 = new Member("山田太郎", 20, "東京都港区");

		ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(
                                     new FileOutputStream("file1")));
		out.writeObject(m1);
		out.close();

		ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(
                                   new FileInputStream("file1")));
		Member m2 = (Member)in.readObject();
		m2.output();
		in.close();
	}
}

class Member implements Serializable {

	private String name;
	private int nenrei;
	private String jusho;

	Member(String str1, int n, String str2)
	{
		name   = str1;
		nenrei = n;
		jusho  = str2;
	}

	void output()
	{
		System.out.println("名前:" + name + " 年齢:" + nenrei + " 住所:" + jusho);
	}
}
		
(出力)
名前:山田太郎 年齢:20 住所:東京都港区