Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Created February 7, 2014 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedunumax/8866498 to your computer and use it in GitHub Desktop.
Save dedunumax/8866498 to your computer and use it in GitHub Desktop.
This class shows how to save a list in a file. And how to load it back to memory.
package org.dedunumax.gist
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
public class DataHandler {
public static void saveData(String fileName, List<Object> list)
throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
fileName));
oos.writeObject(list);
oos.flush();
oos.close();
}
public static List<Object> loadData(String fileName)
throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
fileName));
List<Object> list = (List<Object>) ois.readObject();
ois.close();
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment