点击按钮下载文件
2015-08-31 15:34
288 查看
@RequestMapping("/download.do") public void download(HttpServletRequest request, HttpServletResponse response) throws Exception { String filePath = "文件路径"; FileInputStream fis = null; OutputStream os = null; try { fis = new FileInputStream(filePath); os = response.getOutputStream();// 取得输出流 response.reset();// 清空输出流 response.setHeader("Content-disposition", "attachment; filename=" + filePath.substring(filePath.lastIndexOf("/") + 1));// 设定输出文件头 response.setContentType("application/x-download"); byte[] mybyte = new byte[8192]; int len = 0; while ((len = fis.read(mybyte)) != -1) { os.write(mybyte, 0, len); } os.close(); } catch (IOException e) { throw e; } }
相关文章推荐
- 这种东西Skype莫名啟動
- fragment应用实例二
- shiro—安全配置
- Matlab风格的Plot类for opencv
- 如何使用Struts 2防止表单重复提交?
- 18. jQuery - 尺寸
- handlebars-----each循环使用方法
- __import__简介
- OCV与CPPR模式的理解
- Linux内核构成
- Rails Javascript 只在需要的页面中加载
- HDU1009 - FatMouse' Trade (贪心)
- VC6 go to definition不好用解决方法
- 对于linux-c编译调试信息的部分理解.
- 用Eclipse开发JSF时,是标签出现自动提醒
- Redis info参数总结(转)
- dom4j 读取xml
- IOS第15天(2,事件处理hitTest练习)
- 微软Win10商店开发方面更新:新增多种广告工具包功能
- 判断一个字符串是否是合法IP地址