Jayyrus
Jayyrus

Reputation: 13051

Android - How to write to /mnt/local/

what i've to do with my app is to download some files and write in /mnt/local/.

This is what i try:

String baseDir = Environment.getRootDirectory().getAbsolutePath()+"/mnt/local/mydir" //mydir exists.
FileOutputStream fOut = new FileOutputStream(baseDir);

What i get is:

11-08 18:40:29.799: W/System.err(26464): java.io.FileNotFoundException: /system/mnt/local/htdocs: open failed: ENOENT (No such file or directory)
11-08 18:40:29.800: W/System.err(26464):    at libcore.io.IoBridge.open(IoBridge.java:409)
11-08 18:40:29.801: W/System.err(26464):    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
11-08 18:40:29.802: W/System.err(26464):    at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
11-08 18:40:29.803: W/System.err(26464):    at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
11-08 18:40:29.803: W/System.err(26464):    at support.Support.downloadFile(Support.java:45)
11-08 18:40:29.804: W/System.err(26464):    at task.OfflineUpdate.updateFromArchive(OfflineUpdate.java:84)
11-08 18:40:29.805: W/System.err(26464):    at task.OfflineUpdate.update(OfflineUpdate.java:77)
11-08 18:40:29.805: W/System.err(26464):    at task.OfflineUpdate.access$3(OfflineUpdate.java:74)
11-08 18:40:29.805: W/System.err(26464):    at task.OfflineUpdate$1.run(OfflineUpdate.java:59)
11-08 18:40:29.806: W/System.err(26464):    at java.lang.Thread.run(Thread.java:856)
11-08 18:40:29.807: W/System.err(26464): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
11-08 18:40:29.808: W/System.err(26464):    at libcore.io.Posix.open(Native Method)
11-08 18:40:29.810: W/System.err(26464):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-08 18:40:29.810: W/System.err(26464):    at libcore.io.IoBridge.open(IoBridge.java:393)
11-08 18:40:29.812: W/System.err(26464):    ... 9 more

i don't know how to access to that dir.. can someone enlighten me?

Upvotes: 0

Views: 497

Answers (2)

ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

It seems (from name) that mydir is directory (not file), so you can't write to it.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006604

This is not possible, except perhaps on a rooted device with the app running as superuser, as otherwise you have no read or write access there.

To get rid of the /system/ prefix, delete Environment.getRootDirectory().getAbsolutePath()+ from your code.

Upvotes: 2

Related Questions