以下是start.mp4文件的SD卡路径。我能够以读取模式获取此文件,但无法在rw模式下打开。我也给了运行时权限。 它引发了一个例外:
/storage/3263-6232/piyush/Download/start.mp4:open failed:EACCES(Permission denied)
这是代码:
//This is the sd-card path of the file which needs to be edited
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();
}
In the above code I have taken sdcardpath to a file which exists in sdcard. Than after that whenever I tried to open that file in outputstream using RandomAccessFile it gives FilenotFound Exception:
/storage/3263-6232/piyush/Download/start.mp4: open failed: EACCES (Permission denied)
答案 0 :(得分:0)
如果您使用的是Android 6及更高版本,则应该提出运行时权限请求 那样:
private void requestPermission() {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
和你的onCreate:
public void onCreate(){
requestPermission();
}