/* * 下载
* param:filepath文件绝对路径 */ public void downLoad(HttpServletRequest request,HttpServletResponse response) throws IOException{ String file = request.getParameter("filepath"); int in = file.lastIndexOf("/"); String fileName = file.substring(in+1, file.length()); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename="+URLEncoder.encode(fileName,"UTF-8")); bis=new BufferedInputStream(new FileInputStream(file)); bos=new BufferedOutputStream(response.getOutputStream()); byte[] by=new byte[2048]; int bytesRead; while(-1!=(bytesRead=bis.read(by,0,by.length))){ bos.write(by, 0, bytesRead); } bis.close(); bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); }finally { if(bis!=null){ bis.close(); } if(bos!=null){ bos.close(); } } }
