1

I'm trying to read a file from the sdcard created by 3rd party app and I get an error: I/System.out: Exception java.io.FileNotFoundException: /storage/emulated/0/export.csv: open failed: EACCES (Permission denied) I'm using Android Studio installing on a Asus Nexus 7 tablet running Marshmallow.

My manifest file includes:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test.imagechooser">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application....

and I added

private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};

to my MainActivity.java file. Code for getting the file is:

File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"export.csv");
System.out.println(file.toString());
System.out.println(file.exists());
if (file.exists()) System.out.println(file.canRead());
checkExternalMedia();
StringBuilder text = new StringBuilder();
try {
    BufferedReader br = new BufferedReader(new FileReader(file));
    ...
    br.close();
 }
 catch (IOException e) {
        System.out.println("Exception " + e);
 }

The checkExternalMedia method is copied from Write a file in external storage in Android and claims that read and write permission are set to true. However, while my file.exists() returns true, file.canRead() returns false and the BufferedReader statement causes the FileNotFoundException. Somebody suggested to disconnect from the PC or add a / to export.csv but none of that had any effect. Any other ideas?

Community
  • 1
  • 1
Ann
  • 21
  • 2

0 Answers0