Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import com.sun.org.apache.regexp.internal.RE;
- import java.io.*;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws IOException, ClassNotFoundException {
- Recipe r = new Recipe("Recipe2", "Something and...", "don't bake it");
- serialize(r);
- //Recipe r = deserialize();
- //System.out.println(r.title);
- //System.out.println(r.indgredients);
- //System.out.println(r.text);
- }
- public static void serialize(Recipe r) throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream("myObj.ser");
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
- objectOutputStream.writeObject(r);
- }
- public static Recipe deserialize() throws IOException, ClassNotFoundException {
- FileInputStream fileInputStream = new FileInputStream("myObj.ser");
- ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
- Recipe r = (Recipe) objectInputStream.readObject();
- return r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement