gpt4 book ai didi

android - Android 上的异常 'open failed: EACCES (Permission denied)'

转载 作者:IT老高 更新时间:2023-10-28 12:51:54 35 4
gpt4 key购买 nike

我得到了

open failed: EACCES (Permission denied)

就行了OutputStream myOutput = new FileOutputStream(outFileName);

我检查了根目录,并尝试了 android.permission.WRITE_EXTERNAL_STORAGE

我该如何解决这个问题?

try {
InputStream myInput;

myInput = getAssets().open("XXX.db");

// Path to the just created empty db
String outFileName = "/data/data/XX/databases/"
+ "XXX.db";

// Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);

// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}

// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
buffer = null;
outFileName = null;
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

最佳答案

Google 在 Android Q 上有一项新功能:用于外部存储的过滤 View 。对此的快速修复是将此代码添加到 AndroidManifest.xml 文件中:

<manifest ... >
<!-- This attribute is "false" by default on apps targeting Android Q. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>

您可以在此处阅读更多信息:https://developer.android.com/training/data-storage/use-cases

编辑:我开始被否决,因为这个答案对于 Android 11 来说已经过时了。所以看到这个答案的人请转到上面的链接并阅读说明。

关于android - Android 上的异常 'open failed: EACCES (Permission denied)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8854359/

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