title: Android: java.io.FileNotFoundException even though file can be viewed on browser
body: <p>I'm trying to download an image file within my app but I keep getting "java.io.FileNotFoundException" even though I can view the image on my browser. Here is the code that suppose to download the file. You could test the link on browser</p>
  
  <pre><code>new Thread(new Runnable() {
  
              @Override
              public void run() {
  
                  String filepath = Environment.getExternalStorageDirectory().getAbsolutePath();
                  String sample = "https://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg";
                  try
                  {   
                    URL url = new URL(sample);
                    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                    urlConnection.setRequestMethod("POST");
                    urlConnection.setDoOutput(true);                   
                    urlConnection.connect();                  
  
  
                    File SDCardRoot = new File(Environment.getExternalStorageDirectory(),"Yandere/Wallpapers");
                    SDCardRoot.mkdirs();
                    String filename="downloadedFile.jpg";   
                    Log.i("Local filename:",""+filename);
                    File file = new File(SDCardRoot,filename);
                    if(file.createNewFile())
                    {
                      file.createNewFile();
                    }                 
                    FileOutputStream fileOutput = new FileOutputStream(file);
                    InputStream inputStream = urlConnection.getInputStream();
                    int totalSize = urlConnection.getContentLength();
                    int downloadedSize = 0;   
                    byte[] buffer = new byte[1024];
                    int bufferLength = 0;
                    while ( (bufferLength = inputStream.read(buffer)) &gt; 0 ) 
                    {                 
                      fileOutput.write(buffer, 0, bufferLength);                  
                      downloadedSize += bufferLength;                 
                      Log.i("Progress:","downloadedSize:"+downloadedSize+"totalSize:"+ totalSize) ;
                    }             
                    fileOutput.close();
                    if(downloadedSize==totalSize) filepath=file.getPath();    
                  } 
                  catch (MalformedURLException e) 
                  {
                    e.printStackTrace();
                  } 
                  catch (IOException e)
                  {
                    filepath=null;
                    e.printStackTrace();
                  }}
          }).start();
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> 08-05 16:36:28.032: W/System.err(17064): java.io.FileNotFoundException: https://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg
  08-05 16:36:28.032: W/System.err(17064):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
  08-05 16:36:28.032: W/System.err(17064):    at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
  08-05 16:36:28.032: W/System.err(17064):    at angel.util.Downloader$1.run(Downloader.java:52)
  08-05 16:36:28.032: W/System.err(17064):    at java.lang.Thread.run(Thread.java:856)
  </code></pre>