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("alert(\"you only can download the file, can't do the folder!\");history.back();");
}
}catch(FileNotFoundException e){
PrintWriter out=response.getWriter();
out.print("alert('Sorry,the file could not be found');history.back();");
}catch(Exception e){
PrintWriter out=response.getWriter();
out.print("alert('while downloading,the error happens.');history.back();");
}
}