Created
March 31, 2012 04:27
-
-
Save Morse-Code/2259261 to your computer and use it in GitHub Desktop.
Quick and dirty native Array serialization and deserialization.
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 class Serializer { | |
public static void main(String[] args) throws Exception { | |
// Serialize an int[] | |
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("test.ser")); | |
out.writeObject(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); | |
out.flush(); | |
out.close(); | |
// Deserialize the int[] | |
ObjectInputStream in = new ObjectInputStream(new FileInputStream("test.ser")); | |
int[] array = (int[]) in.readObject(); | |
in.close(); | |
// Print out contents of deserialized int[] | |
System.out.println("It is " + (array instanceof Serializable) + " that int[] implements Serializable"); | |
System.out.print("Deserialized array: " + array[0]); | |
for (int i=1; i<array.length; i++) { | |
System.out.print(", " + array[i]); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment