title: java.io.filenotfoundexception open failed eacces (permission denied) on device
body: <p>The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage.<br>
  But when I tried it with a device with no internal storage, only with external storage I get the following exception.<br></p>
  
  <blockquote>
    <p>java.io.filenotfoundexception open failed eacces (permission denied)</p>
  </blockquote>
  
  <pre><code>public void downloadFile(String dlUrl, String dlName) {
      int count;
  
      HttpURLConnection con = null;
      InputStream is = null;
      FileOutputStream fos = null;
  
      try {
          URL url = new URL( dlUrl );
          con = (HttpURLConnection) url.openConnection();
          con.setDoInput(true);
          con.connect();
  
          is = url.openStream();
          String dir = Environment.getExternalStorageDirectory() + Util.DL_DIRECTORY;
          File file = new File( dir );
          if( !file.exists() ){
              file.mkdir();
          }
  
          Util.LOG_W(TAG, "Downloading: " + dlName + " ...");
  
          fos = new FileOutputStream(file + "/" +  dlName);
          byte data[] = new byte[1024];
  
          while( (count = is.read(data)) != -1 ){
              fos.write(data, 0, count);
          }
  
          Util.LOG_D(TAG, dlName + " Download Complete!");
  
  
      } catch (Exception e) {
          Util.LOG_E(TAG, "DOWNLOAD ERROR = " + e.toString() );
          bServiceDownloading = false;
      }
      finally{
          try {
              if( is != null)
                  is.close();
              if( fos != null)
                  fos.close();
              if( con != null)
                  con.disconnect();
          } catch (Exception e) {
              Util.LOG_E(TAG, "CLOSE ERROR = " + e.toString() );
          }
      }
  }
  </code></pre>
  
  <p>And in manifest file I has the following:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <p>Any suggestions what maybe the cause?
  By the way <strong>Environment.getExternalStorageDirectory()</strong> returns <strong>/mnt/sdcard/</strong> and <strong>file.mkdir()</strong> return false.</p>