Here you can find the source of obj2Bytes(Object obj)
public static byte[] obj2Bytes(Object obj)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class Main { public static byte[] obj2Bytes(Object obj) { byte[] result = null; try {/*from ww w.j ava2s . c om*/ ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream oo = new ObjectOutputStream(bo); oo.writeObject(obj); result = bo.toByteArray(); bo.close(); oo.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; } }