java - open failed: EACCES (Permission denied) on SD card -
i can't use filewriter file on sd card have following permissions in manifest
<uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" />
i using following code
file selected = new file("/storage/extsdcard/", "00 - copy.txt"); filewriter fw; try { fw = new filewriter(selected, false); fw.write(content); fw.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
i getting following in logcat, knowing /storage/extsdcard/00 - copy.txt exists.
07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ java.io.filenotfoundexception: /storage/extsdcard/00 - copy.txt: open failed: eacces (permission denied) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:456) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ java.io.fileoutputstream.<init>(fileoutputstream.java:87) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ java.io.fileoutputstream.<init>(fileoutputstream.java:127) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ java.io.filewriter.<init>(filewriter.java:96) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ tk.hasankassem.supererase.mainactivity$5.run(mainactivity.java:302) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ caused by: android.system.errnoexception: open failed: eacces (permission denied) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ libcore.io.posix.open(native method) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ libcore.io.blockguardos.open(blockguardos.java:186) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:442) 07-14 14:50:48.722 18216-19903/tk.hasankassem.supererase w/system.err﹕ ... 4 more
i have tried using environment.getexternalstoragedirectory(), didn't work too.
update when use environment.getexternalstoragedirectory() writes internal storage , not sd card.
the following permissions should defined outside <application>
tag.
<uses-permission android:name="android.permission.write_external_storage" />
<uses-permission android:name="android.permission.read_external_storage" />
Comments
Post a Comment