private void downValid(HttpServletResponse response,NetDiskFile netDiskFile)throws Exception{
try{
if(netDiskFile!=null){
File f = new File(netDiskFile.getAttach());
//文件流的输入
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
response.reset();
response.setCharacterEncoding("gb2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition",
"attachment; filename="+this.toUtf8String(netDiskFile.getFilename())+"."+netDiskFile.getSuffix());
byte[] buf = new byte[1024];
int len = 0;
//文件流的输出
OutputStream output = response.getOutputStream();
while ((len = br.read(buf)) > 0){
output.write(buf, 0, len);
}
br.close();
output.close();
}else{
PrintWriter out=response.getWriter();
out.println("");
}
}catch(FileNotFoundException e){
PrintWriter out=response.getWriter();
out.print("");
}catch(Exception e){
PrintWriter out=response.getWriter();
out.print("");
}
}
手写不容易,望采纳,万分感激。
取消
评论