我寫了一些代碼,以斷絕文件下載到客戶機:大文件中的Java下載使用FileCopyUtils.copy
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.setHeader("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();
}
此代碼工作正常比8M小,但不適合大文件的文件。如果你們給我一些提示,我將不勝感激。
感謝, 尼克
會發生什麼?你遇到異常還是隻是掛起? – sstendal 2011-02-23 21:17:34
當我在tomcat上部署我的應用程序時,它只是傳輸8M(有時是16M)的75M文件而不顯示任何錯誤消息。當我點擊打開文件時,我只知道問題。 – Nick 2011-02-23 21:47:12