首页 > 其他 > 详细

大文件下载---之内存溢出问题解决

时间:2019-12-05 21:06:31      阅读:405      评论:0      收藏:0      [点我收藏+]
InputStream fis = new BufferedInputStream(new FileInputStream(file));   //用BufferedInputStream读取文件
response.reset();
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=" + new String(file.getName().getBytes(), "iso-8859-1"));
response.addHeader("Content-Length", "" + file.length());
OutputStream out = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
byte[] buffer = new byte[1024 * 1024];
int i;
while ((i = fis.read(buffer)) != -1) {
    out.write(buffer, 0, i);
}
fis.close();
out.flush();
out.close();

 

大文件下载---之内存溢出问题解决

原文:https://www.cnblogs.com/nihaorz/p/11991635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!