ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); try { oos.writeObject(someObject); } finally { oos.close(); } byte[] someObjectBytes = baos.toByteArray();//someObjectBytes就是你要的东西