大文件下載---之內存溢出問題解決


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-2025 CODEPRJ.COM