标签:
@RequestMapping(value = "/downloadtradeinfo") public void downloadtradeinfo(Model model, HttpServletRequest request,HttpServletResponse response) { try { String modlename="文件FOO.doc"; String templateFilePath = "D:"+File.separator+modlename; BufferedInputStream bis=null; BufferedOutputStream bos=null; OutputStream fos=null; InputStream fis = null; File file = new File(templateFilePath); fis= new FileInputStream(file); bis = new BufferedInputStream(fis); fos= response.getOutputStream(); bos= new BufferedOutputStream(fos); response.setHeader("Content-disposition", "attachment;filename="+java.net.URLEncoder.encode(modlename, "UTF-8")); int bytesRead=0; byte[] buffer= new byte[8192]; while((bytesRead=bis.read(buffer,0,8192))!=-1){ bos.write(buffer,0,bytesRead); } bos.flush(); bis.close(); bos.close(); fos.close(); fis.close(); } catch (Exception e) { e.printStackTrace(); } }
标签:
原文地址:http://blog.csdn.net/u010081710/article/details/43525493