import java.io.*; public class Person implements Serializable { public String firstName; public String lastName; private String password; transient Thread worker; public Person(String firstName, String lastName, String password) { this.firstName = firstName; this.lastName = lastName; this.password = password; } public String toString() { return new String(lastName + ", " + firstName); } } class WritePerson { public static void main(String [] args) { Person p = new Person("Fred", "Wesley", "cantguessthis"); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream( new FileOutputStream("Person.ser")); oos.writeObject(p); } catch (Exception e) { e.printStackTrace(); } finally { if (oos != null) { try {oos.flush();} catch (IOException ioe) {} try {oos.close();} catch (IOException ioe) {} } } } } class ReadPerson { public static void main(String [] args) { ObjectInputStream ois = null; try { ois = new ObjectInputStream( new FileInputStream("Person.ser")); Object o = ois.readObject(); System.out.println("Read object " + o); } catch (Exception e) { e.printStackTrace(); } finally { if (ois != null) { try {ois.close();} catch (IOException ioe) {} } } } }