下面是start.mp4文件的sdcard路径。我可以在读取模式下获取此文件,但不能在rw
模式下打开。我也给了运行时权限。它引发一个异常:
/storage/3263-6232/piyush/Download/start.mp4: open failed: EACCES (Permission denied)
码:
String sdCardPath = "/storage/3263-6232/piyush/Download/start.mp4";
File file = new File(sdCardPath );
try{
RandomAccessFile rfs = new RandomAccessFile(file, "rw");
rfs.seek(file.length());
rfs.close();
} catch (IOException e) {
e.printStackTrace();
}
在上面的代码中,我将
sdcardpath
带到sdcard中存在的文件。然后,每当我尝试使用
RandomAccessFile
在outputstream中打开该文件时,它都会给出FilenotFound Exception
:/storage/3263-6232/piyush/Download/start.mp4: open failed: EACCES (Permission denied)
最佳答案
您的Manifest
看起来像这样吗?uses-permission
标记必须在应用程序标记之外<manifest> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ... <application> ... <activity> ... </activity> </application></manifest>
PS:如果您正在使用Post M设备进行测试,请确保在对文件进行任何操作之前先征询WRITE_EXTERNAL_STORAGE
权限。