struts,取得oracle存放blob数据保存为文件,在线等
在upload文件到oracle的blob字段,现在想把它取回,既是通过获得输入流转回成文件,在jsp中弹出窗口保存该文件。
我搜索到类似的帖子,可是都不成功。
例如:转贴
<%@page import="java.io.*"%>
<%
String pathsavefile;//要下载的文件
String fileName;//保存窗口中显示的文件名
fileName=response.encodeURL(new String(fileName.getBytes(),"ISO8859_1"));//
response.reset();
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
ServletOutputStream out = response.getOutputStream();
InputStream inStream=new FileInputStream(pathsavefile);
//循环取出流中的数据
byte[] b = new byte[1024];
int len;
while((len=inStream.read(b)) >0)
out.write(b,0,len);
}
out.close();
inStream.close();
}
catch (Exception e)
{
System.out.println(e);
}
%>
这里是从文件中获得,我想从blob中的流转换成文件
String filename="测试.doc"
InputStream inStream = null;
//读出流用getBinaryStream()方法。
inStream = rs.getBlob("dfile").getBinaryStream();
文件名已经指定。
大家帮忙看看,弄好马上给分。