对象转为字节数组

public static byte[] convertToByteArray(Object obj) throws IOException {
        ObjectOutputStream os = null;
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000);
        os = new ObjectOutputStream(new BufferedOutputStream(byteStream));
        os.flush();
        os.writeObject(obj);
        os.flush();
        byte[] sendBuf = byteStream.toByteArray();
        os.close();
        return sendBuf;
    }
View Code

posted @ 2013-10-22 09:00  smith789  阅读(222)  评论(0编辑  收藏  举报