Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chap01;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by vitaly on 28.06.17.
- */
- public class Foo implements Serializable {
- private List<Integer> list;
- Foo (List list) {
- this.list = list;
- }
- public List<Integer> getList() {
- return list;
- }
- public static void main(String[] args) throws IOException, ClassNotFoundException {
- List<Integer> list = new ArrayList<>();
- list.add(12);
- list.add(12312);
- Foo foo = new Foo(new ArrayList());
- FileOutputStream fileOut =
- new FileOutputStream("/home/vitaly/foo.ser");
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(foo);
- out.close();
- fileOut.close();
- FileInputStream fileIn = new FileInputStream("/home/vitaly/foo.ser");
- ObjectInputStream in = new ObjectInputStream(fileIn);
- Foo newFoo = (Foo) in.readObject();
- System.out.println(newFoo.getList());
- in.close();
- fileIn.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement