Created
September 23, 2016 13:12
-
-
Save zhaohangbo/f2f36b68a57b2279142ecaebaa4fdbb1 to your computer and use it in GitHub Desktop.
Java Serializable Object to Byte Array
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
http://stackoverflow.com/questions/2836646/java-serializable-object-to-byte-array | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ObjectOutputStream out = null; | |
try { | |
out = new ObjectOutputStream(bos); | |
out.writeObject(yourObject); | |
out.flush(); | |
byte[] yourBytes = bos.toByteArray(); | |
... | |
} finally { | |
try { | |
bos.close(); | |
} catch (IOException ex) { | |
// ignore close exception | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment