当我试图打开FileInputStream时,我得到一个例外,即文件打开权限被拒绝。
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" />
答案 0 :(得分:3)
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
。