public class SerialTest { public static void main(String[] args) throws IOException { //序列化 Person person=new Person(1234,"wang"); FileOutputStream fos = new FileOutputStream("Person.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(person); oos.flush(); oos.close(); } @Test public void deserialTest() throws IOException, ClassNotFoundException { //反序列化 Person person; FileInputStream fis = new FileInputStream("Person.txt"); ObjectInputStream ois = new ObjectInputStream(fis); person = (Person) ois.readObject(); ois.close();; System.out.println("Person Deserial:"+person); } }