Android Question java.io.FileNotFoundException

mc73

Well-Known Member
Licensed User
Longtime User
I occasionally get the following error from some (very few) users:

Exception:
Code: Copy
java.io.FileNotFoundException: /data/data/myapp/files/shared/myfile.txt: open failed: ENOENT (No such file or directory)
libcore.io.IoBridge.open (IoBridge.java:456)
java.io.FileOutputStream.<init> (FileOutputStream.java:87)
anywheresoftware.b4a.objects.streams.File.OpenOutput (File.java:373)
anywheresoftware.b4a.objects.streams.File.WriteString (File.java:261)
I'm using a
Code: Copy
rp.GetSafeDirDefaultExternal("shared")
in order to get the directory needed.
I suspect this is a permissions' problem, maybe users deny access to my app.
Anyone else experienced such error? Thank you in advance!

PS: I notice this error only to Android Version 6 and prior. Hope this helps.
 
Last edited:
its really /data/data/ ? it looks odd in folder organization
 
Upvote 0
Doesn't look like a permission issue.

Are you sure that the file is actually there?
Maybe there is no external storage at all. Check File.ExternalWritable.
There is no file there I'm using file. writestring to write to a new file.
Guess I could check externalwritable, but shouldn't this be somewhere inside the getsafeexternal? Just asking.
Interestingly, most crashes come from a certain Lenovo model and all others are very few.
 
Upvote 0
Just noticed, seeing a posted example, that I don't have the following in the manifest:
Code: Copy
AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)

I'm targeting 26, is there any chance that this causes an issue?
 
Upvote 0
Your code will fail on Android 4.4- devices without it.
I see.
Perhaps then I should really check for externalWritable, as you already suggested, and at least, inform users that app cannot be used without it.
 
Upvote 0
Back
Top