title: java.io.FileNotFoundException: /storage/emulated/0/downloadedfilem.jpg (Permission denied)
body: <p>i am trying to download and store image using Async task in android , when clicking download button getting following error.</p>
  
  <pre><code>    W/System.err: java.io.FileNotFoundException: /storage/emulated/0/downloadedfilem.jpg (Permission denied)
  12-07 11:01:00.120 28478-28540/myoracle.com.quotes W/System.err:     at java.io.FileOutputStream.open(Native Method)
  12-07 11:01:00.120 28478-28540/myoracle.com.quotes W/System.err:     at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:221)
  12-07 11:01:00.120 28478-28540/myoracle.com.quotes W/System.err:     at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:108)
  12-07 11:01:00.120 28478-28540/myoracle.com.quotes W/System.err:     at myoracle.com.quotes.WallpaperDeatilsActivity$ImageDownload.doInBackground(WallpaperDeatilsActivity.java:113)
  12-07 11:01:00.120 28478-28540/myoracle.com.quotes W/System.err:     at myoracle.com.quotes.WallpaperDeatilsActivity$ImageDownload.doInBackground(WallpaperDeatilsActivity.java:91)
  </code></pre>
  
  <p><strong>WallpaperActivity.java</strong></p>
  
  <pre><code>class ImageDownload extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected String doInBackground(String... params) {
          int count;
          try {
  
              String root = Environment.getExternalStorageDirectory().toString();
  
              System.out.println("Downloading");
              URL url = new URL(params[0]);
  
              URLConnection conection = url.openConnection();
              conection.connect();
              // getting file length
              int lenghtOfFile = conection.getContentLength();
  
              // input stream to read file - with 8k buffer
              InputStream input = new BufferedInputStream(url.openStream(), 8192);
  
              // Output stream to write file
              System.out.println(root);
              OutputStream output = new FileOutputStream(root+"/downloadedfilem.jpg");
              byte data[] = new byte[1024];
              long total = 0;
              while ((count = input.read(data)) != -1) {
                  total += count;
                  // writing data to file
                  output.write(data, 0, count);
                  System.out.println(count);
              }
              // flushing output
              output.flush();
              // closing streams
              output.close();
             input.close();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <ol>
  <li>Android Target Api 7.1.1</li>
  </ol>
  
  <p>Permissions added in manifest </p>
  
  <ol>
  <li><p>android.permission.READ_EXTERNAL_STORAGE  </p></li>
  <li><p>android.permission.WRITE_EXTERNAL_STORAGE</p></li>
  </ol>