当我试图下载一个大文件是从服务器260MB的,我得到这个错误:java.lang.OutOfMemoryError: Java heap space.
我相信我的堆大小小于252MB。有什么办法可以在不增加堆大小的情况下下载大文件?如何下载大文件时内存问题在Java
如何下载大文件没有得到这个问题?我的代码如下:
String path= "C:/temp.zip";
response.addHeader("Content-Disposition", "attachment; filename=\"test.zip\"");
byte[] buf = new byte[1024];
try {
File file = new File(path);
long length = file.length();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
ServletOutputStream out = response.getOutputStream();
while ((in != null) && ((length = in.read(buf)) != -1)) {
out.write(buf, 0, (int) length);
}
in.close();
out.close();
您能够增加对JVM堆大小?即:JAVA -Xm512m -Xmx512m MyClass的 –
是的,但我想,要知道如果我能做到这一点不增加JVM堆大小,因为我们有一个要求,以约1GB的大容量文件下载到10 GB –