Last active
December 15, 2015 00:58
-
-
Save mertsimsek/5176188 to your computer and use it in GitHub Desktop.
Code snippet about saving and loading on JAVA by using serialization. In this one, i prefer to save/load an arraylist. You can customize it.
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
public static void savingArrayList(File saveFile , ArrayList<MyClass> myArrayList ){ | |
try { | |
FileOutputStream fos = new FileOutputStream(saveFile); | |
GZIPOutputStream gzos = new GZIPOutputStream(fos); | |
ObjectOutputStream out = new ObjectOutputStream(gzos); | |
out.writeObject(myArrayList); | |
out.flush(); | |
out.close(); | |
}catch (IOException e) { | |
System.out.println(e); | |
} | |
} | |
public static void loadingArrayList(File selectedFile){ | |
try { | |
FileInputStream fis = new FileInputStream(selectedFile); | |
GZIPInputStream gzis = new GZIPInputStream(fis); | |
ObjectInputStream in = new ObjectInputStream(gzis); | |
ArrayList<MyClass> myNewArrayList = (ArrayList<MyClass>)in.readObject(); | |
in.close(); | |
}catch (Exception e) {System.out.println(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment