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();
