文件下载间歇性失败?

时间:2015-09-08 20:24:18

标签: java

我继承了一个用于传输文件的java应用程序。从3个月前开始,当用户尝试下载文件(他们从下拉列表中选择文件并提交表单)时,打开/保存对话框将打开,但如果他们选择打开,则文件无法下载,如果他们选择保存,则“另存为”对话框无法打开。

问题间歇性地发生,但它影响了大约10%的下载尝试。下面是用于执行下载的代码,它似乎有什么问题吗?我可以在打开/保存对话框打开后等待4-5秒复制,然后选择打开或保存。

String fileName=downloadForm.getFileName();
String filePath=downloadForm.getDirPath()+File.separator;
File dPath=new File(filePath);
File f=new File(dPath,downloadForm.getFileName());
FileInputStream inStream=new FileInputStream(f);     
int size=new Long(f.length()).intValue();

response.setContentLength(size);
response.setContentType("application/x-file-download");
response.setHeader("Content-disposition","attachment; filename="+ fileName);
response.setHeader("Cache-Control", "max-age=" + MAX_AGE_IN_SECONDS);
ServletOutputStream outStream = response.getOutputStream();
CopyUtils.copy(inStream,outStream); // Copies input stream to output stream.
inStream.close();
outStream.flush();

谢谢,

0 个答案:

没有答案
相关问题