'open failed: EACCES (Permission denied)' exception occurs on Android.

Asked 2 years ago, Updated 2 years ago, 31 views

OutputStream myOutput = newFileOutputStream(outFileName); The following error occurs:

open failed: `EACCES (Permission denied)

Android. Permission.I also tried WRITE_EXTERNAL_STORAGE.

How do we solve this problem?

try {
    InputStream myInput;

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

    // Path of generated empty db
    String outFileName = "/data/data/XX/databases/"
            + + "XXX.db";

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

    // Transfer byte data from input file to output file
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }

    // The part that closes the stream
    myOutput.flush();
    myOutput.close();
    myInput.close();
    buffer = null;
    outFileName = null;
}
catch (IOException e1) {
    // // TODO Auto-generated catch block
    e1.printStackTrace();
}

android

2022-09-22 21:15

1 Answers

I've had the same problem before. I think the location of the use-permission is wrong. Fix it like this.

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

          ...

        <application>
            ...
              <activity> 
                    ...
              </activity

        </application>

    </manifest> 

The uses-permission tag must be outside the application tag.


2022-09-22 21:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.