title: FileDownloader at the android it is showing no errors but the download does not start
body: <p>I am trying to download a simple <code>.pdf</code> file I have tried logs but no errors and nothing. I tried to debug but the same till yesterday it worked like charm but not today, I didn't change nothing at this part of the code.
  I am based at this question and answer at SO.</p>
  
  <p><a href="https://stackoverflow.com/a/24748227/9560126">https://stackoverflow.com/a/24748227/9560126</a>  </p>
  
  <p>Below is the code.</p>
  
  <p>Sometimes at the LogCat it shows me only like message something like this.</p>
  
  <p><code>com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) FileDownloader.downloadFile</code></p>
  
  <p>at this line of code.</p>
  
  <pre><code>inputStream = urlConnection.getInputStream();
  </code></pre>
  
  <p>The code of Url connection.</p>
  
  <p><code>urlConnection.getResponseCode()</code>   </p>
  
  <p>It is returning <code>405</code></p>
  
  <p><code>MainActivity.java</code></p>
  
  <pre><code>String newEntry = "http://www.axmag.com/download/pdfurl-guide.pdf";
  new DownloadFile().execute(newEntry, "maven.pdf");
  
    private static class DownloadFile extends AsyncTask&lt;String, Void, Void&gt;{
  
      @Override
      protected Void doInBackground(String... strings) {
          String fileUrl = strings[0];   // -&gt; http://maven.apache.org/maven-1.x/maven.pdf
          String fileName = strings[1];  // -&gt; maven.pdf
          String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
          File folder = new File(extStorageDirectory, "testthreepdf");
          folder.mkdir();
  
          File pdfFile = new File(folder, fileName);
  
          try{
              pdfFile.createNewFile();
          }catch (IOException e){
              e.printStackTrace();
          }
          FileDownloader.downloadFile(fileUrl, pdfFile);
          return null;
      }
  }
  </code></pre>
  
  <p><code>FileDownloader.java</code></p>
  
  <pre><code>public class FileDownloader {
  private static final int  MEGABYTE = 1024 * 1024;
  
  public static void downloadFile(String fileUrl, File directory){
      try {
  
          URL url = new URL(fileUrl);
          HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
          urlConnection.setRequestMethod("GET");
          urlConnection.setDoOutput(true);
          urlConnection.connect();
  
          InputStream inputStream;
          inputStream = urlConnection.getInputStream();
          FileOutputStream fileOutputStream = new FileOutputStream(directory);
          int totalSize = urlConnection.getContentLength();
  
          byte[] buffer = new byte[MEGABYTE];
          int bufferLength = 0;
          while((bufferLength = inputStream.read(buffer))&gt;0 ){
              fileOutputStream.write(buffer, 0, bufferLength);
          }
          fileOutputStream.close();
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
   }
  }
  </code></pre>
  
  <p><code>AndroidManifest.XML</code></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>