Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; public class Main { public static byte[] ObjectToByte(Object obj) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(obj); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] Bytes = bos.toByteArray(); return Bytes; } }