实现文件下载
2015-12-29 23:50
162 查看
response实现文件下载
String path =this.getServletContext().getRealPath("/download/美女.jpg"); String filename = path.substring(path.lastIndexOf("\\")+1); //如果下载文件是中文,则文件名需要经过url编码 // response.setHeader("content-disposition", "attachment;filename=" + (filename)); response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename,"UTF-8")); InputStream in =null; OutputStream out = null; try { in = new FileInputStream(path); int len = 0; byte buffer[] = new byte[1024]; out =response.getOutputStream(); while ((len=in.read(buffer))>0) { out.write(buffer,0,len); } }finally{ if (in !=null) { in.close(); } if (out !=null) { out.close(); } }
相关文章推荐
- C++中的内存对齐
- 从扎克伯格捐450亿看程序员前景
- 随机取出数组中的某些值,并删除它们array_splice,array_slice
- 可读性设计规范
- Delphi中的内存对齐 与 Packed关键字
- 节日
- 【mysql】关于innodb_file_format
- 太上感应篇0007
- springMVC返回数据的乱码问题
- project 计算器
- win32api显示BMP图片的最简单方案
- MySQL用户权限管理详解
- leetcode笔记:Subsets II
- php与Microsoft SQL Server
- 技术安家了
- win10下启动mysql解压版
- ViewPager使用详解
- 多声道音频指南(二):那些年,那些技术,那些名词
- 关于Xcode7中添加不了libresolv.dylib等类似库的问题
- JVM启动参数大全