Exception 'open failed: EACCES (Permission denied)' on Android

前端 未结 30 1978
[愿得一人]
[愿得一人] 2020-11-22 00:59

I am getting

open failed: EACCES (Permission denied)

on the line OutputStream myOutput = new FileOutputStream

30条回答
  •  一整个雨季
    2020-11-22 01:46

    Strangely after putting a slash "/" before my newFile my problem was solved. I changed this:

    File myFile= new File(Environment.getExternalStorageDirectory() + "newFile");
    

    to this:

    File myFile= new File(Environment.getExternalStorageDirectory() + "/newFile");
    

    UPDATE: as mentioned in the comments, the right way to do this is:

    File myFile= new File(Environment.getExternalStorageDirectory(), "newFile");
    

提交回复
热议问题