try{ObjectInputStream is =newObjectInputStream(newFileInputStream("E:/Person.txt"));ArrayList<Person> list =newArrayList<Person>();
list =(ArrayList<Person>) is.readObject();for(int i =0; i < list.size(); i++){System.out.println(list.get(i).toString());}}catch(FileNotFoundException e){// TODO Auto-generated catch block
e.printStackTrace();}catch(IOException e){// TODO Auto-generated catch block
e.printStackTrace();}catch(ClassNotFoundException e){// TODO Auto-generated catch block
e.printStackTrace();}
java对象序列化,将对象存入到文件中,并读取出来要将对象序列化,需要对象实现序列化接口public class Person implements Serializable {}通过java 的 ObjectOutputStream的writeObject()方法将对象序列化的数据 写到指定的文件中try { ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream("E:/Person.txt")); os