我正在使用休眠将压缩文件存储在数据库中,我已经创建了 Blob 文件Hibernate.createBlob(input stream)
现在我想扭转这个过程并将 Blob 转换为文件,这样我就可以用 Zip4j 打开它我应该怎么做呢?我试图这样做,但我总是得到一个例外
File file = new File("origfile.zip"); try { InputStream is = blob.getBinaryStream(); <- exception FileOutputStream opt = new FileOutputStream(file); int read = 0; byte[] bytes = new byte[1024]; while ((read = is.read(bytes)) != -1) { opt.write(bytes, 0, read); }
例外是:
2013-07-03 18:38:35,482 [DEBUG] [HibernateTransactionManager,doBegin(),569] - Exposing Hibernate transaction as JDBC transaction [com.mchange.v2.c3p0.impl.NewProxyConnection@69875a82] java.sql.SQLException: could not reset reader at org.hibernate.lob.BlobImpl.getBinaryStream(BlobImpl.java:106) at org.hibernate.lob.SerializableBlob.getBinaryStream(SerializableBlob.java:62) at com.gleeb.backbonetemplates.services.LivePreviewService.prepareDesignForLivePreview(LivePreviewService.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
谢谢。