java blob 转文件

Blob blob = (Blob) obyte;
InputStream is=blob.getBinaryStream();
String filePath = "c://a.pdf";
FileOutputStream fos = new FileOutputStream(filePath);
//定义缓冲区
int length=(int)blob.length();
     byte bt[] =new byte[length];
     try {
             //向缓冲区中 读取数据
             while ((length = is.read(bt)) != -1) {
                     //把缓冲区的述据 写出去
                     fos.write(bt);
                 }
         } catch (IOException ex) {
        
         }
             //关闭输入流
             is.close();
             //关闭输出流
             fos.close();

你可能感兴趣的:(java)