将数据库中存储的二进制转换为本地文件,前提需要知道文件类型
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
File file = new File("ff."+filetype);
OutputStream output = new FileOutputStream(file);
BufferedInputStream input = null;
int length;
while (rs.next()) {
byte b[] = new byte[4096];
Blob blob = rs.getBlob("C_CONTENT");
input = new BufferedInputStream(blob.getBinaryStream());
do {
length = input.read(b);
if (length != -1) {
output.write(b, 0, length);
}
} while (length > 0);
}
output.flush();
output.close();
if (input != null) {
input.close();
}
将数据库二进制流转为本地文件
猜你喜欢
转载自wanghuanqiu.iteye.com/blog/1614501
今日推荐
周排行