title: Servlet read/output binary file nor same checksum as original file
body: <p>I have a servlet (JSP) that reads a file from disk and sends it as http response.</p>
  
  <p>The downloaded file has not the same sha1sum that the original and some files seems to be corrupted.</p>
  
  <p>My code is this:</p>
  
  <pre><code>File file = new File((String)application.getAttribute("path")+"/"+item);
  if (!file.exists()){
      RequestDispatcher dispatcher = application.getRequestDispatcher("/not_found.jsp?item="+item);
      dispatcher.forward(request, response);
      return;
  }
  response.setContentType("application/octet-stream");
  response.setHeader("Content-Disposition",
  "attachment;filename=\""+item+"\"");
  Locale.setDefault(new Locale("ES","ve"));
  FileInputStream fileIn = new FileInputStream(file);
  ServletOutputStream outs = response.getOutputStream();
   byte[] outputByte = new byte[4096];
  //copy binary contect to output stream
  System.out.println(new java.util.Date()+"\tStart download\t"+item+"\t"+request.getRemoteAddr()+"\t"+request.getRemoteHost());
  while(fileIn.read(outputByte, 0, 4096) != -1)
  {
      outs.write(outputByte, 0, 4096);
  }
  fileIn.close();
  outs.flush();
  outs.close();
  System.out.println(new java.util.Date()+"\tEnd Download\t"+item+"\t"+request.getRemoteAddr()+"\t"+request.getRemoteHost());
  </code></pre>
  
  <p><strong>Why does downloaded file have different sha1sum as original file and why some but not all downloaded files are corrupt?</strong></p>