Guest User

Untitled

a guest
Oct 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class World {
  2.  
  3. public World() { }
  4.  
  5. public class Person implements Serializable {
  6. private static final long serialVersionUID = 1L;
  7. private String name;
  8. public Person() { }
  9. public String toString() {
  10. return "{" + name + "}";
  11. }
  12. }
  13.  
  14. private Person person = new Person();
  15.  
  16. synchronized public void save() {
  17. try {
  18. FileOutputStream fos = new FileOutputStream("save.ser");
  19. BufferedOutputStream bos = new BufferedOutputStream(fos);
  20. ObjectOutputStream oos = new ObjectOutputStream(bos);
  21. oos.writeObject(person);
  22. oos.close();
  23. } catch (Exception e) {
  24. // TODO: handle exception
  25. e.printStackTrace();
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment