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?

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)


 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…