/**
* 文件下载
* @param response
* @param downloadPath
* @param docName
*/
public void downLoadFile(
HttpServletResponse response,String downloadPath, String docName) {
response.setContentType("text/html;charset=utf-8"); BufferedInputStream bis = null;
BufferedOutputStream bos = null; File file = new File(downloadPath); try {
response.addHeader("Content-Length", String.valueOf(file.length()));
byte[] buff = new byte[2048];
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());
int bytesRead;
while ((bytesRead = bis.read(buff, 0, buff.length)) != -1) {
bos.write(buff, 0, buff.length);
} } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if(bis !=null){
bis.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(bos !=null){
bos.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}
}

  

最新文章

  1. Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 拒绝访问。
  2. angular-笔记
  3. 慕课编程题JS选项卡切换
  4. Nessus常见问题整理
  5. 数据库 基础篇3(mysql语法)
  6. Android数据存储之sharedpreferences与Content Provider
  7. jbrowse 的配置与使用gff, vcf, fa, bed, bam
  8. SQL SERVER 中identity用法
  9. 将批量下载的博客导入到手机后,通过豆约翰博客阅读器APP(Android手机)进行浏览,白字黑底,保护眼睛,图文并茂。
  10. Java通过代理server上网
  11. 阐述 QUEST CENTRAL FOR DB2 八罪
  12. AOP 在javascript 中的使用
  13. GPU版的tensorflow在windows上的安装时的错误解决方案
  14. Java中 &&与&,||与|的区别
  15. 第六十四天 JS基础操作
  16. CentOS7下安装Python3并保留Python2
  17. catkin-make: command not found 错误解决
  18. Spring的AOP基于AspectJ的注解方式开发2
  19. 可视化展示attention(seq2seq with attention in tensorflow)
  20. Python3学习之路~2.10 修改haproxy配置文件

热门文章

  1. IE & table & border & border-collapse & bug
  2. hdu 1814 2-sat 输出字典最小的和任意序列的 模板题
  3. android 实现照相功能 照片存放在SID卡中,将照片显示在Image中
  4. TYVJ1716 上帝造题的七分钟
  5. 【NOIP2017练习】跳跃切除子序列(模拟)
  6. UVA 116_ Unidirectional TSP
  7. Redis基于客户端分片的集群案例(待实践)
  8. Android Api Demos登顶之路(四十五)Loader-->Cursor
  9. MongoDb 学习教程
  10. LiveWriter高亮显示方法专题