Android 上的异常“打开失败:EACCES(权限被拒绝)" [英] Exception 'open failed: EACCES (Permission denied)' on Android

查看:40
本文介绍了Android 上的异常“打开失败:EACCES(权限被拒绝)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要了

打开失败:EACCES(权限被拒绝)

就行 OutputStream myOutput = new FileOutputStream(outFileName);

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

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:

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

uses-permission 标签需要在 application 标签之外.

The uses-permission tag needs to be outside the application tag.

这篇关于Android 上的异常“打开失败:EACCES(权限被拒绝)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆