Here you can find the source of ObjectToByte(Serializable obj)
public static byte[] ObjectToByte(Serializable obj)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static byte[] ObjectToByte(Serializable obj) { byte[] bytes = null; try {/*from www .j a va 2 s . c o m*/ // object to bytearray ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream oo = new ObjectOutputStream(bo); oo.writeObject(obj); bytes = bo.toByteArray(); bo.close(); oo.close(); } catch (Exception e) { e.printStackTrace(); } return bytes; } }