title: How to fix java.io.IOException: An existing connection was forcibly closed by the remote host when downloading a file
body: <p>I'm trying to download a file in my application, but following exception is thrown:</p>
  
  <blockquote>
    <p>org.apache.catalina.connector.ClientAbortException:
    java.io.IOException: An existing connection was forcibly closed by the
    remote host</p>
  </blockquote>
  
  <p>I've read most of related questions on SO, specially <a href="https://stackoverflow.com/questions/45482585/java-io-ioexception-an-existing-connection-was-forcibly-closed-by-the-remote-ho">this one</a>, but none helped me to get through this exception.</p>
  
  <p>Code:</p>
  
  <pre><code>response.setContentType(mimeType);
  response.setContentLength((int) file.length());
  response.addHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
  
  InputStream inputStream = new FileInputStream(file);
  OutputStream responseOutPutStream = response.getOutputStream();
  
  byte buffer[] = new byte[32 * 1024];
  int bytes;
  while ((bytes = inputStream.read(buffer)) != -1) {
      responseOutPutStream.write(buffer, 0, bytes);
  }
  responseOutPutStream.flush();
  inputStream.close();
  responseOutPutStream.close();
  </code></pre>
  
  <p><code>mimeType</code>is <code>application/octet-stream</code></p>
  
  <p>also, I implemented this code using <code>FileCopyUtils.copy(inputStream, responseOutPutStream);</code> but same result.</p>
  
  <p>The request is sent from <em>ExtJS</em> application using <code>&lt;a&gt;</code> tag.</p>
  
  <p>We tried to send a <strong>Get</strong> request via <em>Ajax</em>, but that didn't solve to problem.</p>
  
  <p>There's almost 2 days since i'm searching and debugging, couldn't find any way to solve this problem.</p>
  
  <p>how to fix this?</p>
  
  <p>Best Regards</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>more information: I use Spring Boot as underlying framework and the code above is called in a controller class (annotated with <code>@Controller</code> annotation)</p>