File 无法从servlet打开文件

File 无法从servlet打开文件,file,servlets,internet-explorer-8,File,Servlets,Internet Explorer 8,我试图在IE中从servlet打开pdf文件。它给出的错误为com.ibm.wsspi.webcontainer.ClosedConnectionException:OutputStream在写入过程中遇到错误 下面是代码片段 我在操作系统写入(缓冲数据,0,读取)的第行出错 在Mozilla中,我没有收到任何错误,但文件也没有在此处打开您是否设置了任何断点以查看失败的地方?缓冲区读取数据是否如预期的那样?如果不是根据mime类型设置内容类型,而是强制将其设置为“应用程序/八位字节流”,是否会

我试图在IE中从servlet打开pdf文件。它给出的错误为
com.ibm.wsspi.webcontainer.ClosedConnectionException:OutputStream在写入过程中遇到错误

下面是代码片段
我在操作系统写入(缓冲数据,0,读取)的第
行出错


在Mozilla中,我没有收到任何错误,但文件也没有在此处打开

您是否设置了任何断点以查看失败的地方?缓冲区读取数据是否如预期的那样?如果不是根据mime类型设置内容类型,而是强制将其设置为“应用程序/八位字节流”,是否会出现相同的错误?
File file = new File("Desktop\\Workflow\\123456.pdf");
if(!file.exists()) {
    throw new ServletException("File doesn't exists on server.");
}
System.out.println("File location on server::"+file.getAbsolutePath());
InputStream fis = new FileInputStream(file);
String mimeType = ctx.getMimeType(file.getAbsolutePath());
response.setContentType(mimeType != null? mimeType:"application/octet-stream");
response.setContentLength((int) file.length());
response.setHeader("Content-Disposition", "attachment; filename=\"123456.pdf\"");
ServletOutputStream os = response.getOutputStream();
byte[] bufferData = new byte[1024];
int read=0;
while((read = fis.read(bufferData))!= -1) {
    System.out.println("read::"+read);    
    os.write(bufferData, 0, read);
}
os.flush();
os.close();
fis.close();