java下载zip文件socket write error

今天用java下载zip文件的时候老是出现如下错误,从网上找了错误原因,感觉答案解决不了我的问题:

ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:413)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:342)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:438)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:426)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)

代码如下:
File file = new File("d:/zhangrm/aa/test.zip");
response.reset();
response.setHeader("Content-Disposition", "attachment;filename="
.concat(String.valueOf(URLEncoder.encode(file.getName(), "UTF-8"))));
response.setContentType("application/x-msdownload");
response.setContentLength((int) file.length());

    try {

        InputStream inputStream = new FileInputStream(file);
        BufferedInputStream buffInput = new BufferedInputStream(inputStream);

        //写文件  
        byte[] b = new byte[1024];
        long k = 0;

        OutputStream outputStream = response.getOutputStream();
        BufferedOutputStream buffOutput=new BufferedOutputStream(outputStream);

         while (k < file.length()) {
             int j = buffInput.read(b, 0, 1024);
             k += j;
             buffOutput.write(b, 0, j);
         }
        buffOutput.flush();
        inputStream.close();
        buffInput.close();
        outputStream.close();
        buffOutput.close();

       // deleteFile(pathTo);
        //deleteFile(Const.ZIPFILENAME);

    } catch (IOException e) {
        log.error("数据下载失败!");
        e.printStackTrace();
    }

    望大神帮忙解决下!!!小妹不胜感激!
查看全部
xihawuyou
xihawuyou
2015/09/01 08:25
  • java
  • 点赞
  • 收藏
  • 回答
    私信

1个回复