1.Spring自带方法,定义输出流就可以写入文件
final OutputStream os; os = new FileOutputStream(new File("300.zip")); FileCopyUtils.copy(blob.getBinaryStream(), os);
2.转成byte[]后写入
Blob blob = rs.getBlob("FSTREAM");
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
InputStream inputStream = blob.getBinaryStream();
byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据
int rc = 0;
while ((rc = inputStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] fStreamByte = swapStream.toByteArray(); //in_b为转换之后的结果
final OutputStream os;
os = new FileOutputStream(new File("300.zip"));
os.write(fStreamByte);
os.close();