FileNotFoundException storage.txt (Read-only file system)

Penko

Active Member
Licensed User
Longtime User
Hello guys!

I've tried searching about this issue but there doesn't seem to exist much information.

Here is my code:

AppSettings
B4X:
   ' File storage
   Dim mainStorageDir As String : mainStorageDir =  File.DirInternal
   Dim mainStorageFile As String : mainStorageDir = "storage.txt"

Save/Load file
B4X:
   Sub loadFile()
   
   If(File.Exists(AppSettings.MainStorageDir, AppSettings.MainStorageFile) = False) Then
      saveFile
   End If
   
       filesMap = File.ReadMap(AppSettings.MainStorageDir, AppSettings.MainStorageFile)
   End Sub
   
   Sub saveFile()
   
   If(filesMap.IsInitialized = False) Then
      filesMap.Initialize
   End If
   
   File.WriteMap(AppSettings.MainStorageDir, AppSettings.MainStorageFile, filesMap)
   
   End Sub

After I start the application, it shows this error:
Error in sub:savefile. java.io.FileNotFoundException: /storate.txt (read-only file system). Is this a phone issue or what?

Sorry, tried searching myself and I am asking because I haven't found anything which solves it for me.
 

klaus

Expert
Licensed User
Longtime User
Unfortunately with the information in your post it's impossible to you give you a concrete answer.

Did you Dim mainStorageDir and m
ainStorageFile in the Proccess_Globals or in the Globals routine of the AppSettings module?
They must be in
Proccess_Globals.

Are the load and save routines in the
AppSettings module ?
If yes, remove the module prefix of the variables.

You could also add a Log in the save routine to see if the filename is OK.

In the save routine if the map is not initialized do you really want to save an empty map ?

Best regards.
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Klaus, thank you for your detailed reply.

This is the situation:
- AppSettings - module for storing AppSettings. It includes the dir and file variables in Process_Globals.
- the load and save functions are in the other module, called "Common".
- Logging returns "storage.txt" so it seems okay. I don't know how internal memory should look like but seems okay to me.
- Blank map would be the case when the user starts the application for the first time. It is not something bad as the user will fill some views with data which will store it in the MAP.

I even tried adding at least one file to the map before storing it for the first time but that didn't change anything but the error still persists.

B4X:
Sub saveFile()
   
   If(filesMap.IsInitialized = False) Then
      filesMap.Initialize
      
      Dim mapie As FILES
      mapie = constructFile("test", Null, "aaa", "aaa",DateTime.Now, DateTime.Now)
      
      filesMap.Put(mapie.key, mapie)
      
   End If
   
   File.WriteMap(AppSettings.MainStorageDir, AppSettings.MainStorageFile, filesMap)
   
   End Sub
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
' File storage
Dim mainStorageDir As String : mainStorageDir = File.DirInternal
Dim mainStorageFile As String : mainStorageDir = "storage.txt"

Error in sub:savefile. java.io.FileNotFoundException: /storate.txt (read-only file system). Is this a phone issue or what?

That location is read-only, so you cannot write to it!

Use something like File.DirExternal or File.DirDefaultExternal.

Rolf
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@rbsoft
Sorry, but DirInternal is readable and writeable.
DirAssets is only readable !

@Penko
The problem is here:
B4X:
Dim mainStorageDir As String     : mainStorageDir = File.DirInternal
Dim mainStorageFile As String    : mainStorageDir = "storage.txt"
It must bee:
B4X:
Dim mainStorageDir As String     : mainStorageDir = File.DirInternal
Dim mainStorageFile As String    : mainStorageFile = "storage.txt"
When you say that Logging did give the right value, are you sure?

Best regards.
 
Upvote 0
Top