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?
source to share
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");
source to share
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();
source to share