large files Download in Java using FileCopyUtils.copy
I wrote some codes to download files from the Sever to the clients machines:
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(fileNpath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String mimetype = servletContext.getMimeType(fileNpath);
response.setBufferSize(fSize);
response.setContentType(mimetype);
response.s开发者_如何学编程etHeader("Content-Disposition", "attachment; filename=\""+ fileName + "\"");
response.setContentLength(fSize);
try {
FileCopyUtils.copy(in, response.getOutputStream());
in.close();
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
This code works fine for the files smaller than 8M but not for larger files. I will be grateful if you guys give me some hints.
Thanks, Nick
There is not much to go on here. In Tomcat there are various ways to set the maximum file upload size.
For example in the tomcat server.xml, there is a maxPostSize setting. I really do not know enough about your server to say specifically where to look.
Setting the heap size in tomcat solved the problem.
So I set CATALINA_OPTS=-Xms512m -Xmx512m in apache-tomcat-7.0.8\bin\catalina.bat
I also set maxPostSize="0"
精彩评论