FileNotFoundException EACCES (Permission Denied)

2.4k views Asked by At

I'm getting an exception that file open permission is denied when I'm trying to open a FileInputStream.

 File myFile = new File(Environment.getExternalStorageDirectory()
           .getAbsolutePath() + "/test/test.txt");
 try {
      FileInputStream inStream = new FileInputStream(myFile); // crash

Here's the stacktrace:

 System.err﹕ java.io.FileNotFoundException: /storage/emulated/0/test/test.txt: open failed: EACCES (Permission denied)
 System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
 System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:76)

 ...

 Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
 at libcore.io.Posix.open(Native Method)
 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
 at libcore.io.IoBridge.open(IoBridge.java:442)

And yes, I do have the permissions in my manifest:

<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE" />
1

There are 1 answers

5
CommonsWare On BEST ANSWER

Android is case sensitive. Replace ANDROID.PERMISSION with android.permission:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Also, you should only need one of those permissions. If you are planning on writing to external storage, you should not also need READ_EXTERNAL_STORAGE.