title: What happens when a file being downloaded is modified on the server?
body: <p>I'm downloading a zip file from a server but keep getting corrupted file.  I have a slow connection and I know that the server keeps updating the file frequently.  Is this why I get corrupted files?  I would assume the network protocol should be smart enough to avoid this kind of situations.</p>
  
  <pre><code>private void downloadFile(String urlString, String fileName)
          throws MalformedURLException, IOException {
      InputStream input = new URL(urlString).openConnection().getInputStream();
      FileOutputStream output = new FileOutputStream(fileName);
      int bufferSize = 153600;
      byte[] buffer = new byte[bufferSize];
      int totalBytesRead = 0;
      int bytesRead = 0;
  
      while ((bytesRead = input.read(buffer)) &gt; 0) {
          output.write(buffer, 0, bytesRead);
          buffer = new byte[bufferSize];
          totalBytesRead += bytesRead;
      }
  
      output.close();
      input.close();
  }
  </code></pre>
  
  <p>Thanks!</p>