Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Json {
  4.  
  5. public void serialize(String name, Object object){
  6. try{
  7. FileOutputStream fs = new FileOutputStream(name+".ser");
  8. ObjectOutputStream os = new ObjectOutputStream(fs);
  9. os.writeObject(object);
  10. os.close();
  11.  
  12. } catch (Exception e) {
  13. e.printStackTrace();
  14. }
  15. }
  16.  
  17. public Object deserialize(String name){
  18. try {
  19. FileInputStream strumienPlk = new FileInputStream(name+".ser");
  20. ObjectInputStream os = new ObjectInputStream(strumienPlk);
  21. Object obj = os.readObject();
  22. return obj;
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. return null;
  26. }
  27. }
  28.  
  29. public static void main(String args[]){
  30.  
  31. Contact contact = new Contact(1,"Pawel", "535231060");
  32. ContactEntry contactEntry = new ContactEntry(contact);
  33.  
  34. Json json = new Json();
  35. json.serialize("asd", contactEntry);
  36. ContactEntry con = (ContactEntry) json.deserialize("asd");
  37. System.out.println(con.getAvailability().getCurrentDay());
  38.  
  39.  
  40.  
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement