Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package com.company;
  2.  
  3. import com.sun.org.apache.regexp.internal.RE;
  4.  
  5. import java.io.*;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) throws IOException, ClassNotFoundException {
  11. Recipe r = new Recipe("Recipe2", "Something and...", "don't bake it");
  12. serialize(r);
  13.  
  14. //Recipe r = deserialize();
  15. //System.out.println(r.title);
  16. //System.out.println(r.indgredients);
  17. //System.out.println(r.text);
  18.  
  19. }
  20.  
  21. public static void serialize(Recipe r) throws IOException {
  22. FileOutputStream fileOutputStream = new FileOutputStream("myObj.ser");
  23. ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
  24. objectOutputStream.writeObject(r);
  25. }
  26.  
  27. public static Recipe deserialize() throws IOException, ClassNotFoundException {
  28. FileInputStream fileInputStream = new FileInputStream("myObj.ser");
  29. ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
  30. Recipe r = (Recipe) objectInputStream.readObject();
  31. return r;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement