BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));
byte[] stb = new byte[bis.available()];
int length = 0;
length = bis.read(stb);
bis.close();
response.setContentLength(length);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream(), length);
bos.write(stb, 0, length);
bos.close();
加粗这段是下载时后台内存溢出的原因,文件稍大一点就溢出了
解决方案(SpringUtils):
FileInputStream is = new FileInputStream(file);
FileCopyUtils.copy(is, os);
----公司案例,待学习。