Guest User

Untitled

a guest
Dec 11th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5.  
  6. /*
  7. * To change this template, choose Tools | Templates
  8. * and open the template in the editor.
  9. */
  10.  
  11. /**
  12. *
  13. * @author themuser
  14. */
  15. public class DeserializeMyClassToBePersisted {
  16. public static void main(String [] args) {
  17.  
  18. String filename = "class.ser";
  19. if(args.length > 0) {
  20. filename = args[0];
  21. }
  22.  
  23. // Deserialize the previously saved
  24. // PersistentTime object instance.
  25. MyClassToBePersisted myClass = null;
  26. FileInputStream fis = null;
  27. ObjectInputStream in = null;
  28. try {
  29. fis = new FileInputStream(filename);
  30. in = new ObjectInputStream(fis);
  31. myClass = (MyClassToBePersisted)in.readObject();
  32. in.close();
  33. } catch(IOException ex) {
  34. ex.printStackTrace();
  35. } catch(ClassNotFoundException ex) {
  36. ex.printStackTrace();
  37. }
  38.  
  39. // print out restored myClass
  40. System.out.println("BEFORE : " + myClass);
  41.  
  42. // print out the current myClass
  43. System.out.println("AFTER : " + new MyClassToBePersisted());
  44. }
  45. }
Add Comment
Please, Sign In to add comment