gpt4 book ai didi

android - 写入 sdCard 时权限被拒绝

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:05 26 4
gpt4 key购买 nike

我正在尝试将文件写入 SDCard,但我在 logcat 中遇到错误:

01-24 09:03:33.647: W/System.err(3353): java.io.FileNotFoundException: /mnt/sdcard/fun/itisfun.txt: open failed: EACCES (Permission denied)
01-24 08:24:28.007: W/System.err(3353): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
01-24 09:03:33.756: W/System.err(3353):at libcore.io.Posix.open(Native Method)

这里是我写入 SDCard 的代码:

File root = null;     
try {
// check for SDcard
root = Environment.getExternalStorageDirectory();
Log.i(TAG,"path.." +root.getAbsolutePath());

//check sdcard permission
if (root.canWrite()){
File fileDir = new File(root.getAbsolutePath()+"/fun/");
fileDir.mkdirs();

File file = new File(fileDir, "itisfun.txt");
FileWriter filewriter = new FileWriter(file);
BufferedWriter out = new BufferedWriter(filewriter);
out.write("I m enjoying......dude");
out.close();
}
} catch(...) {
...
}

list :

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

最佳答案

要写入 Sdcard,您需要在 list 文件中授予权限

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

关于android - 写入 sdCard 时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14475951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com