Java examples for java.io:Serializable
get Bytes From Serialized Object
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static byte[] getBytesFromObject(Serializable data) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream objos = new ObjectOutputStream(os); objos.writeObject(data);//ww w. j ava2s .c om objos.flush(); byte[] result = os.toByteArray(); os.close(); objos.close(); return result; } }