title: FileNotFoundException while getting the InputStream during downloading file to SD card using URLConnection
body: <p>I'm working on application which has workflow like this:</p>
  
  <p>1.parsing home page (using HttpURLConnection, connect(), do stuff, disconnect(), use data),</p>
  
  <p>2.after click on links I made, parsing article or download file based on link.</p>
  
  <p>First step works perfect &amp; 2nd too in case of article, but when I'm trying to download file from specific url and save it to SD card, I got fileNotFoundException in this line:   </p>
  
  <pre><code>  InputStream inputStream = urlConnection.getInputStream();
  </code></pre>
  
  <p>My guide for doing it (downloading file) was code explained here <a href="http://goo.gl/GTBOP" rel="nofollow">http://goo.gl/GTBOP</a> and I set permissions in manifest as required for this action, plus before any download operation I checked MEDIA_MOUNTED &amp; MEDIA_MOUNTED_READ_ONLY state and it seems like that fits nice.</p>
  
  <p>So..I read a lot about this problem on stackOverflow and other places and I tried different suggestions like adding these:</p>
  
  <pre><code>urlConnection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
  urlConnection.setRequestProperty("Accept","*/*");
  </code></pre>
  
  <p>or </p>
  
  <pre><code>System.setProperty("http.keepAlive", "false");
  </code></pre>
  
  <p>but with no success. I'm still stucked with fileNotFoundException. I tried to catch response code from webpage and it says 404.. ?! </p>
  
  <p>It's strange that if I hardcode link to file for downloading from any other site it downloads file without any troubles. So to make it clear I pickup clicked link to fileurl variable but in a next step I just say fileurl="somesite/somefile.ext" everything goes smooth.. From web browser I can download any file that make troubles in my application so I'm confused where is the problem..</p>
  
  <p>Any suggestion please..? 10q</p>