【发布时间】:2017-09-19 10:09:36
【问题描述】:
下面是我的一个 start.mp4 文件的 SD 卡路径。我能够以读取模式获取此文件,但无法以 rw 模式打开。我也给了运行时权限。 它抛出一个异常:
/storage/3263-6232/piyush/Download/start.mp4:打开失败:EACCES(权限被拒绝)
这是代码:
//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)
【问题讨论】:
-
"我能够以读取模式获取此文件,但无法以 rw 模式打开" - 因为您在 Android 4.4+ 上对removable storage 上的任意文件没有读/写访问权限,这并不奇怪。但是,Stack Overflow 是针对编程问题的,你还没有问过问题。
标签: java android android-sdcard randomaccessfile