public class Person implements Serializable { } public class SerializationDemo { public static void serializeDataObject(Person person) { try { FileOutputStream fos = new FileOutputStream("data.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(person); oos.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } public class DeserializationDemo { public static Person deserializeDataObject() { Person person = null; try { FileInputStream fis = new FileInputStream("data.ser"); ObjectInputStream ois = new ObjectInputStream(fis); person = (Person) ois.readObject(); ois.close(); fis.close(); e.printStackTrace(); } return person; } }


上一篇:
下一篇:
切换中文