No write permission to / mnt / extsd

I cannot write to external sd (/ mnt / extsd) in mini x plus h24

I am already inserting into the manifest

The system has two SD cards, the first one is accessible with Environment.getExternalStorageDirectory (), but the second one is only accessible with an absolute path

try{
        File file3 = new File("/mnt/extsd/", "file.txt");
        BufferedWriter writer = new BufferedWriter(new FileWriter(file3));
        writer.write("hello");
        writer.flush();
        writer.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

      

Exception return me this message /mnt/extsd/file.txt: open failed: EACCES (Permissio denied)

Any suggestions?

+3


source to share


4 answers


add below permission to android manifest file.

Write permission

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

      



Allow reading

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

      

+3


source


You need to add permission

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

      

in the AndroidManifest.xml file .

EDIT

If you have already added this permission and are still denied permission, you can write to a read-only directory or you are not allowed to write to the root directory of that directory.



You might want to check if the directory is writable. Somthing like:

file3.canWrite()

      

or you can try adding a child directory before writing

File newDir = new File("/mnt/extsd/myFiles");
newDir.mkdirs();
File file3 = new File(newDir.getAbsolutePath(), "file.txt");

      

+3


source


Just add permission to android manifest file.

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

      

+1


source


if you have already added permissions to your manifest file try with them:

1) File file1 = new File(Environment.getExternalStorageDirectory() + "file.txt");

2) File file2 = new File("file:///mnt/extsd/", "file.txt");

3) File file3 = new File("file:///mnt/sdcard/", "file.txt");

      

and then use

String filepath = "file:///" + file1.getAbsolutePath();

      

0


source







All Articles