title: Downloading on Android - FileNotFoundException but file exists
body: <p>I tried to download a file from a server in Android but all I get is a FileNotFoundException.</p>
  
  <p>My download method works fine for all files I give it, but not on this one specific url.
  The url it is not working on looks like this: <a href="http://server.com/download.aspx?action=geta&amp;sid=12345&amp;file=somedata.xml&amp;client=android" rel="nofollow">http://server.com/download.aspx?action=geta&amp;sid=12345&amp;file=somedata.xml&amp;client=android</a></p>
  
  <p>I see no errors in the url, if I enter it into a webbrowser, i imediately get the file. The permissions are also allright, I can use the method to download every other file from the server, for example with "getfile" instead of "get", but the file i want to download is only accessible through "get", so i can't just replace it.</p>
  
  <p>Anyway, here is my download method:</p>
  
  <pre><code>public String downloadURL (URL url, String fileName) throws IOException {
      String destination = null;
  
      try {           
          destination = Environment.getExternalStorageDirectory() + "/" 
                  + "myapp/" + fileName;
  
          InputStream input = new BufferedInputStream(url.openStream());
          OutputStream output = new FileOutputStream(destination);
  
          byte buffer[] = new byte[1024];
          int bytes = 0;
  
          while ((bytes = input.read(buffer)) != -1) {
              output.write(buffer,0, bytes);
          }
  
          output.flush();
          output.close();
          input.close();
  
      }
      catch (Exception e) {
          Log.e("DOWNLOAD URL", "downloading file failed due to " + e.toString());
      }
  
      return destination; 
  }
  </code></pre>
  
  <p>I'm kind of in despair here, I searched StackOverflow for a while but got no solution, and would be very grateful for help.</p>
  
  <p>EDIT: The error stack, if that is, what I think it is: </p>
  
  <blockquote>
    <p>08-16 17:32:58.530: WARN/System.err(24754): java.io.FileNotFoundException: <a href="http://myfirm.com/download.aspx?action=get&amp;sid=6d62429x-4e1c&amp;file=data.xml&amp;client=android" rel="nofollow">http://myfirm.com/download.aspx?action=get&amp;sid=6d62429x-4e1c&amp;file=data.xml&amp;client=android</a>
    08-16 17:32:58.530: WARN/System.err(24754):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:532)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.net.URL.openStream(URL.java:645)
    08-16 17:32:58.530: WARN/System.err(24754):     at myapp.cont.fetch.Downloader.downloadURL(Downloader.java:412)
    08-16 17:32:58.530: WARN/System.err(24754):     at myapp.cont.fetch.Downloader.getData(Downloader.java:465)
    08-16 17:32:58.530: WARN/System.err(24754):     at myapp.cont.fetch.Downloader$GetFilesTask.doInBackground(Downloader.java:245)
    08-16 17:32:58.530: WARN/System.err(24754):     at myapp.cont.fetch.Downloader$GetFilesTask.doInBackground(Downloader.java:1)
    08-16 17:32:58.530: WARN/System.err(24754):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
    08-16 17:32:58.530: WARN/System.err(24754):     at java.lang.Thread.run(Thread.java:1020)</p>
  </blockquote>