Created
February 8, 2015 03:31
-
-
Save jimexist/ed148061736260ece5dd to your computer and use it in GitHub Desktop.
OOSTest.java
This file contains hidden or 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
| import java.io.*; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| public class OOSTest { | |
| public static void main(String[] args) throws Exception { | |
| try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | |
| ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) { | |
| List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4)); | |
| objectOutputStream.writeObject(list); | |
| try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); | |
| ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) { | |
| System.out.println(String.valueOf(objectInputStream.readObject())); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment