Android Question no such file or directory

Douglas Farias

Expert
Licensed User
Longtime User
hi i m using this code to write a simple ini file
and i have this error
no such file or directory

but File.DirAssets dont is my app folder? o_O

B4X:
File.WriteString(File.DirAssets, "config.ini", "teste=casa")
 

stevel05

Expert
Licensed User
Longtime User
You can't write to File.DirAssets, I would imagine you want File.DirDefaultExternal, which is your apps data directory.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
      If File.Exists(File.DirDefaultExternal, "clickfight" ) = False Then
      File.MakeDir(File.DirDefaultExternal, "clickfight")  
      Else If File.IsDirectory(File.DirDefaultExternal,"clickfight") Then
      FP = File.Combine(File.DirDefaultExternal,"clickfight")
      Else
      FP = File.DirDefaultExternal
      End If

      File.WriteString(FP, "config.ini", "teste=casa")

how to fix

B4X:
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)


LogCat connected to: B4A-Bridge: alps S6-123456789026263
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
Installing file.
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
java.io.FileNotFoundException: /AssetsDir/config.ini: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:448)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:348)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:246)
at click.fight.vallow.perfil._activity_create(perfil.java:359)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at click.fight.vallow.perfil.afterFirstLayout(perfil.java:98)
at click.fight.vallow.perfil.access$100(perfil.java:16)
at click.fight.vallow.perfil$WaitForLayout.run(perfil.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:432)
... 19 more
java.io.FileNotFoundException: /AssetsDir/config.ini: open failed: ENOENT (No such file or directory)
sending message to waiting queue (CallSubDelayed - teste)
Installing file.
** Activity (perfil) Pause, UserClosed = false **
sending message to waiting queue (hc_responsesuccess)
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
java.io.FileNotFoundException: /AssetsDir/config.ini: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:448)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:348)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:246)
at click.fight.vallow.perfil._activity_create(perfil.java:481)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at click.fight.vallow.perfil.afterFirstLayout(perfil.java:98)
at click.fight.vallow.perfil.access$100(perfil.java:16)
at click.fight.vallow.perfil$WaitForLayout.run(perfil.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:432)
... 19 more
java.io.FileNotFoundException: /AssetsDir/config.ini: open failed: ENOENT (No such file or directory)
sending message to waiting queue (CallSubDelayed - teste)
Installing file.
** Activity (perfil) Pause, UserClosed = false **
sending message to waiting queue (hc_responsesuccess)
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:448)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:348)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:246)
at click.fight.vallow.perfil._activity_create(perfil.java:495)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at click.fight.vallow.perfil.afterFirstLayout(perfil.java:98)
at click.fight.vallow.perfil.access$100(perfil.java:16)
at click.fight.vallow.perfil$WaitForLayout.run(perfil.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:432)
... 19 more
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
sending message to waiting queue (CallSubDelayed - teste)
Installing file.
** Activity (perfil) Pause, UserClosed = false **
sending message to waiting queue (hc_responsesuccess)
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:448)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:348)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:246)
at click.fight.vallow.perfil._activity_create(perfil.java:493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at click.fight.vallow.perfil.afterFirstLayout(perfil.java:98)
at click.fight.vallow.perfil.access$100(perfil.java:16)
at click.fight.vallow.perfil$WaitForLayout.run(perfil.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:432)
... 19 more
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
sending message to waiting queue (CallSubDelayed - teste)
Installing file.
** Activity (perfil) Pause, UserClosed = false **
sending message to waiting queue (hc_responsesuccess)
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:448)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:348)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:246)
at click.fight.vallow.perfil._activity_create(perfil.java:493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at click.fight.vallow.perfil.afterFirstLayout(perfil.java:98)
at click.fight.vallow.perfil.access$100(perfil.java:16)
at click.fight.vallow.perfil$WaitForLayout.run(perfil.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:432)
... 19 more
java.io.FileNotFoundException: /config.ini: open failed: EROFS (Read-only file system)
sending message to waiting queue (CallSubDelayed - teste)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
do your app has permissions to write to external storage?
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
I actually forgot it *-*

added this
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
and work

thx stevel and DomManfred
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try this:
B4X:
If File.Exists(File.DirDefaultExternal, "clickfight" ) = False Then
      File.MakeDir(File.DirDefaultExternal, "clickfight")
      FP = File.Combine(File.DirDefaultExternal,"clickfight")
    Else
        If File.IsDirectory(File.DirDefaultExternal,"clickfight") Then
              FP = File.Combine(File.DirDefaultExternal,"clickfight")
          Else
              FP = File.DirDefaultExternal
          End If
    End If
    File.WriteString(FP, "config.ini", "teste=casa")

You had a hole in your if statements, when creating the directory, you didn't update FP.
 
Upvote 0
Top