SerializableBlob全称org.hibernate.lob.SerializableBlob,是在做hibernate SQL查询二进制文件(图片)时未做封装产生的,它和byte数组是不能直接强制转换的,而我们需要的却是byte数组,所以需要有方法进行转换,上网找了下,是利用流进行转换的,应用在项目中能够解决问题,代码如下:
byte[] bytes;
BufferedInputStream bis = null;
try {
SerializableBlob blob = (SerializableBlob) obj[3];
bis = new BufferedInputStream(blob.getBinaryStream());
bytes = new byte[(int)blob.length()];
int len = bytes.length;
int offest = 0;
int read = 0;
while(offest<len&&(read=bis.read(bytes, offest, len-offest))>0){
offest+=read;
}
} catch (Exception e) {
bytes = null;
e.printStackTrace();
} finally{
if(bis!=null){
bis.close();
bis = null;
}
}
希望能帮更多人解决问题!