FileNotFoundException EACCES (Permission Denied)



当我尝试打开文件输入流时,我收到文件打开权限被拒绝的异常。

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

下面是堆栈跟踪:

 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)

是的,我确实在我的清单中拥有权限:

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

Android 区分大小写。将ANDROID.PERMISSION替换为android.permission

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

此外,您应该只需要其中一个权限。如果您计划写入外部存储,则不需要READ_EXTERNAL_STORAGE

相关内容

  • 没有找到相关文章

最新更新