异常“打开失败:EACCES(权限被拒绝)”在Android [英] Exception 'open failed: EACCES (Permission denied)' on Android
本文介绍了异常“打开失败:EACCES(权限被拒绝)”在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到
打开失败:
EACCES(权限被拒绝)
就行了的OutputStream myOutput =新的FileOutputStream(outFileName);
我检查了根,我试图 android.permission.WRITE_EXTERNAL_STORAGE
。
我怎样才能解决这个问题呢?
尝试{
InputStream的myInput;
myInput = getAssets()开(XXX.db)。
//路径刚刚创建的空分贝
字符串outFileName =/数据/数据/ XX /数据库/
+XXX.db;
//打开空分贝的输出流
的OutputStream myOutput =新的FileOutputStream(outFileName);
//将字节从inputfile中的OUTPUTFILE
byte []的缓冲区=新的字节[1024];
INT长;
而((长度= myInput.read(缓冲液))大于0){
myOutput.write(缓冲液,0,长度);
}
//关闭流
myOutput.flush();
myOutput.close();
myInput.close();
缓冲=无效;
outFileName = NULL;
}
赶上(IOException异常E1){
// TODO自动生成的catch块
e1.printStackTrace();
}
解决方案
我有同样的问题...的<使用-许可
是在错误的地方。这是正确的:
<应用>
...
< /用途>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
< /舱单>
在使用-许可
标签必须是应用程序
标记。
I am getting
open failed:
EACCES (Permission denied)
on the line OutputStream myOutput = new FileOutputStream(outFileName);
I checked the root, and I tried android.permission.WRITE_EXTERNAL_STORAGE
.
How can I fix this problem?
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();
}
解决方案
I had the same problem... The <uses-permission
was in the wrong place. This is right:
<application>
...
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
The uses-permission
tag needs to be outside the application
tag.
这篇关于异常“打开失败:EACCES(权限被拒绝)”在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文