blob 转换为byte[]

 BLOB数据库类型,byte[]可以直接保存到数据库

blob 转换为byte[]

public byte[] blobToByte(Blob blob) throws Exception {
byte[] bytes = null;
try {
InputStream in=blob.getBinaryStream();
BufferedInputStream inBuffered = new BufferedInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = inBuffered.read(temp)) != -1) {
out.write(temp, 0, size);
}
inBuffered.close();
in.close();
bytes = out.toByteArray();
} catch(Exception ex){
ex.printStackTrace();
}
return bytes;
}

posted @ 2014-08-12 17:00  Kevin_Zhou_9  阅读(5306)  评论(0编辑  收藏  举报