java io 文件下载
2024-09-30 19:07:51
/**
* 文件下载
* @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();
} }
}
}
最新文章
- Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 拒绝访问。
- angular-笔记
- 慕课编程题JS选项卡切换
- Nessus常见问题整理
- 数据库 基础篇3(mysql语法)
- Android数据存储之sharedpreferences与Content Provider
- jbrowse 的配置与使用gff, vcf, fa, bed, bam
- SQL SERVER 中identity用法
- 将批量下载的博客导入到手机后,通过豆约翰博客阅读器APP(Android手机)进行浏览,白字黑底,保护眼睛,图文并茂。
- Java通过代理server上网
- 阐述 QUEST CENTRAL FOR DB2 八罪
- AOP 在javascript 中的使用
- GPU版的tensorflow在windows上的安装时的错误解决方案
- Java中 &;&;与&;,||与|的区别
- 第六十四天 JS基础操作
- CentOS7下安装Python3并保留Python2
- catkin-make: command not found 错误解决
- Spring的AOP基于AspectJ的注解方式开发2
- 可视化展示attention(seq2seq with attention in tensorflow)
- Python3学习之路~2.10 修改haproxy配置文件
热门文章
- IE &; table &; border &; border-collapse &; bug
- hdu 1814 2-sat 输出字典最小的和任意序列的 模板题
- android 实现照相功能 照片存放在SID卡中,将照片显示在Image中
- TYVJ1716 上帝造题的七分钟
- 【NOIP2017练习】跳跃切除子序列(模拟)
- UVA 116_ Unidirectional TSP
- Redis基于客户端分片的集群案例(待实践)
- Android Api Demos登顶之路(四十五)Loader--&;gt;Cursor
- MongoDb 学习教程
- LiveWriter高亮显示方法专题