title: Android 6.0 Write to external SD Card
body: <p>I tried everything to write on external SD card on Android 6.0, but I am not able to write on it. </p>
  
  <p>I did research on stackoverflow and found lot of things but none works. Here is my code</p>
  
  <pre><code>String extPath = System.getenv("SECONDARY_STORAGE") + "/Android/data/com.gvm.externalstorage.externalstoragetest/";
  File file = new File(extPath,"myFiles");
  
              if (!file.exists()) {
                  boolean dirResult = file.mkdirs();
                  Log.e("Directory Exist", dirResult + " Directory created");
              } else {
                  Log.e("Directory Exist", "Exist");
                  Log.e("Direcotry Path",file.getAbsolutePath());
              }
              //String displayname = fileName.replace("%20", " ");
              File outputFile = new File(file, "mytest5.txt");
              outputFile.createNewFile();
  </code></pre>
  
  <p>This code works on Android 5.0 but not on Android 6.0.</p>
  
  <p>Then I tried this path as well, and that gives me permission error, I have set all permission and managed code for runtime permission as well.</p>
  
  <pre><code>/mnt/media_rw/6AC9-083B
  
  File write failed: java.io.IOException: open failed: EACCES (Permission denied)
  </code></pre>
  
  <p>If anyone can help me it would be great as I am trying this since last 3 days. </p>
  
  <p>Thanks,
  Anvesh</p>