title: how to Save Public File in Android external storage
body: <p>I am developing an android app in which I am downloading a pdf file from internet to the external directory.
  I have tried in many ways but there is always an error.
  I am listing my codes with errors serially below:</p>
  
  <p>1.</p>
  
  <pre><code>String fname=title+".pdf";
  loc="/sdcard"+"/"+fname;
  output=new FileOutputStream(loc);
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>BookActivity(1255): /sdcard/Pragmatic Unit Testing in Java with JUnit.pdf: open failed: EACCES (Permission denied)
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>File outputdir=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
  String fname=title+".pdf";
  loc=outputdir.getAbsolutePath()
  output=new FileOutputStream(loc);
  </code></pre>
  
  <p>Error:
      BookActivity(1172): /storage/sdcard/Download/Node.js for PHP Developers.pdf: open failed: ENOENT (No such file or directory)</p>
  
  <p>I have this permission in my AndroidManifest.xml file:</p>
  
  <pre><code>&lt;!-- Permission: Allow Connect to Internet --&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;!-- Permission: Writing to SDCard --&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
      android:maxSdkVersion="18" /&gt;
  </code></pre>
  
  <p>Please help me out what to do??
  Also if you can please tell me how to save public files in internal storage.</p>
  
  <p>also tried the answer at <a href="https://stackoverflow.com/a/7887114/964741">https://stackoverflow.com/a/7887114/964741</a></p>
  
  <p>but again arror:</p>
  
  <pre><code>BookActivity(1319): /storage/sdcard/Apache Axis2 Web Services, 2nd Edition.pdf: open failed: EACCES (Permission denied)
  </code></pre>