0

I'm getting exception

java.io.FileNotFoundException: /data/data/XX/files/permissions.xml: open failed: EACCES (Permission denied)

when trying to copy file from SD Card to app data location. My code is

File copy = new File((getActivity()
                       .getApplicationContext().getFileStreamPath("permissions.xml")
                        .getPath()));
if (!copy.exists()) {
  try {
    copy.getParentFile().mkdirs();
    copy.createNewFile();
  } catch (Exception err) {
    err.printStackTrace();
  }
}
copyFileUsingChannel(xmlFile, copy);

method copyFileUsingChannel is calling method copyFileUsingStream directly. I have both write and read permissions declared in manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="XX">

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

    <application
...

I have no idea why this exception is thrown. I'm creating file from app package. Should it be caused by extending non-app class? Thanks for any help.

EDIT: Interesting fact I realized: File is created but cannot write content into it

Martin
  • 652
  • 9
  • 27
  • Possible duplicate of [Exception 'open failed: EACCES (Permission denied)' on Android](https://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android) – Swati Garg May 20 '18 at 17:13

2 Answers2

1

Do you grant runtime permission? This is a Documentation Request App Permissions

Amir Hossein
  • 313
  • 1
  • 2
  • 13
0

I solved problem by renaming file from permissions.xml to prms.xml. It seems like reserved word of android.

Martin
  • 652
  • 9
  • 27