异常“打开失败:EACCES(权限被拒绝)”在Android被拒、异常、权限、Android

由网友(做好自己)分享简介:我收到打开失败: EACCES(权限被拒绝) 就行了的OutputStream myOutput =新的FileOutputStream(outFileName); 我检查了根,我试图 android.permission.WRITE_EXTERNAL_STORAG​​E 。我怎样才能解决这个问题呢?尝试{Input...

我收到

  

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

就行了的OutputStream myOutput =新的FileOutputStream(outFileName);

我检查了根,我试图 android.permission.WRITE_EXTERNAL_STORAG​​E

我怎样才能解决这个问题呢?

 尝试{
    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();
}
 

解决方案

我有同样的问题...的<使用-许可是在错误的地方。这是正确的:

 <应用>
        ...

    < /用途>

    <使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
< /舱单>
 

使用-许可标签必须是应用程序标记。

Android O使用效果如何呢 Android O预览版上手体验

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.

阅读全文

相关推荐

最新文章