When I am trying to download a large file which is of 260MB from server, I get this error: java.lang.OutOfMemoryError: Java heap space. I am sure my heap size is less than 252MB. Is there any way I can download large files without increasing heap size?
How I can download large files without getting this issue? My code is given below:
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();