title: Android: Error when saving file to SD Card
body: <p>I've been trying to save a JPG image to the SD Card in order to then scale it down and display it in an ImageView (due to the original size causing an Out of memory error).</p>
  
  <p>Here's the method I use to save the file:</p>
  
  <pre><code>public void saveImage(String src) throws IOException{
          URL url = new URL (src); 
          InputStream input = url.openStream(); 
          try {     
              File storagePath = Environment.getExternalStorageDirectory();
              OutputStream output = new FileOutputStream (new File(storagePath, "myImage.jpg"));     
              try {         
                  byte[] buffer = new byte[1024];         
                  int bytesRead = 0;         
                  while ((bytesRead = input.read(buffer, 0, buffer.length)) &gt;= 0) {
                          output.write(buffer, 0, bytesRead);         
                  }     
              }  
              finally {         
                  output.close();     
              } 
          } 
  
          finally {     
              input.close(); 
          }
      }
  </code></pre>
  
  <p>Then here is when I call on that method and then try to load a scaled down image into memory and put it into the ImageView:</p>
  
  <pre><code>try {
              saveImage(src);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          BitmapFactory.Options options = new BitmapFactory.Options();
  
          options.inSampleSize = 20;
  
  
  
          File storagePath = Environment.getExternalStorageDirectory();
          File file = new File(storagePath, "myImage.jpg");
  
          Bitmap scaledDownImage = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
  
  
          imageFrame1.setImageBitmap(scaledDownImage);
  </code></pre>
  
  <p>However, when I try to run this, I get the LogCat message saying:</p>
  
  <blockquote>
    <p>"java.io.FileNotFoundException: /mnt/sdcard/myImage.jpg: open failed :
    EACCES (Permission denied)"</p>
  </blockquote>
  
  <p>I've also made sure to add</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>to the manifest.</p>
  
  <p>Does anyone have any ideas?</p>
  
  <p>Edit: The error occurs at line 107 and 72, meaning that it occurs when I try to save the image.</p>
  
  <p>Bump: Anyone? Would really appreciate some suggestions.</p>