Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package chap01;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. /**
  8.  * Created by vitaly on 28.06.17.
  9.  */
  10. public class Foo implements Serializable {
  11.     private List<Integer> list;
  12.     Foo (List list) {
  13.         this.list = list;
  14.     }
  15.  
  16.     public List<Integer> getList() {
  17.         return list;
  18.     }
  19.  
  20.     public static void main(String[] args) throws IOException, ClassNotFoundException {
  21.         List<Integer> list = new ArrayList<>();
  22.         list.add(12);
  23.         list.add(12312);
  24.         Foo foo = new Foo(new ArrayList());
  25.  
  26.         FileOutputStream fileOut =
  27.                 new FileOutputStream("/home/vitaly/foo.ser");
  28.         ObjectOutputStream out = new ObjectOutputStream(fileOut);
  29.         out.writeObject(foo);
  30.         out.close();
  31.         fileOut.close();
  32.         FileInputStream fileIn = new FileInputStream("/home/vitaly/foo.ser");
  33.         ObjectInputStream in = new ObjectInputStream(fileIn);
  34.         Foo newFoo = (Foo) in.readObject();
  35.         System.out.println(newFoo.getList());
  36.         in.close();
  37.         fileIn.close();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement