Created
February 7, 2014 16:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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