title: Posting a large file in Android
body: <p>I sometimes get an <code>OutOfMemoryError</code> when posting a large file in Android. This is the code I'm using. Am I doing something wrong? </p>
  
  <pre><code>HttpURLConnection con = (HttpURLConnection) url.openConnection();
  con.setRequestMethod("POST");
  con.setDoInput(true);
  con.setDoOutput(true);
  ostream = new DataOutputStream(con.getOutputStream());
  byte[] buffer = new byte[1536];
  int count;
  while ((count = fileInput.read(buffer)) != -1) {
      ostream.write(buffer, 0, count); // This sometimes causes OutOfMemoryError
  }
  ostream.flush();
  </code></pre>
  
  <p>Would calling <code>ostream.flush()</code> inside the <code>while</code> loop do any good?</p>