import java.io.*;
import java.util.ArrayList;
class User implements Serializable {   //定义类User，并实现串行化接口
String name;
	    String id;
	    transient  String passWord;
	    public User(String name,String id,String passWord){
		    this.name=name;
		    this.id=id;
		    this.passWord=passWord;
	    }
}
public class Example8_10{ 
       public static void main(String args[])throws IOException,ClassNotFoundException, OptionalDataException{         //在main方法声明中抛出可能的异常
        ArrayList a=new ArrayList();                   //定义ArrayList对象，存放User类的对象
		   a.add(new User("小王","xiaowang","123"));
		   a.add(new User("小李","xiaoli","123"));
        ObjectOutputStream objs=new ObjectOutputStream(new FileOutputStream("test.dat"));
		   objs.writeObject(a);
		   objs.close();
		   ObjectInputStream objg=new ObjectInputStream(new FileInputStream("test.dat"));  	
       ArrayList b=(ArrayList)objg.readObject();
		   objg.close();
		   User user1=(User)b.get(0);
		   User user2=(User)b.get(1);
		   System.out.println("\tname"+"\tid   "+"\tpassWord");
		   System.out.println("\t"+user1.name+"\t"+user1.id+"\t"+user1.passWord);
		   System.out.println("\t"+user2.name+"\t"+user2.id+"\t"+user2.passWord);
	    }
}
