title: Android slow file download
body: <p>I am downloading on my android app. I am using a local network connection and the download is really slow.</p>
  
  <p>Here's he code I am using:</p>
  
  <pre><code>URL url = new URL(ep.getFileURL());
  File destFile = new File(&lt;path to sd card file&gt;);
  
  URLConnection uCon = url.openConnection();
  InputStream is = uCon.getInputStream();
  OutputStream os = new FileOutputStream(destFile);
  
  int progress = 0;
  int lastProgress = 0;
  int totalSize = uCon.getContentLength();
  int downloadedSize = 0;
  byte[] buffer = new byte[4096];
  int count = -1;
  while((count = is.read(buffer)) != -1)
  {
      os.write(buffer, 0, count);
  
  downloadedSize = downloadedSize + count;
      progress = (int)(downloadedSize * 100.0 / totalSize);
      if(progress - lastProgress &gt;= 5) {
          publishProgress(progress);
          lastProgress = progress;
      }
  }
  
  os.close();
  </code></pre>
  
  <p>Do you spot any problems? thank you.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I tested my code using your suggestions and I got these results:</p>
  
  <pre>
  # Download times tests #
  
  Without bufferedoutput
  Downloading file:      1 ms, Start download
  Downloading file:      179812 ms, Finished downloading 54687744 bytes
  Downloading file: end, 179813 ms
  
  With bufferedoutput
  Downloading file:      1 ms, Start download
  Downloading file:      178312 ms, Finished downloading 54687744 bytes
  Downloading file: end, 178313 ms
  
  With httpclient
  Downloading file: begin
  Downloading file:      1 ms, Start download
  Downloading file:      178241 ms, Finished downloading 54687744 bytes
  Downloading file: end, 178242 ms
  </pre>
  
  <p>So, using Buffered streams or using HttpClient directly, doesn't change anything...</p>
  
  <p>I also should have mentioned that my code is inside a AsyncTask, so publishProgress() actually runs on a separated thread already...</p>
  
  <p>Thank you for your help.</p>