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


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();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2024 CODEPRJ.COM