Created
September 23, 2016 13:12
-
-
Save zhaohangbo/f2f36b68a57b2279142ecaebaa4fdbb1 to your computer and use it in GitHub Desktop.
Revisions
-
zhaohangbo created this gist
Sep 23, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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 } }