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.
Unfortunately with the information in your post it's impossible to you give you a concrete answer.
Did you Dim mainStorageDir and mainStorageFile 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 ?
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
Ah, Klaus, thank you !!! It seems I should stop working until 3 am.
In fact, as I elaborated in my last post, I logged the variables and the output was "/storage.txt". I don't know how Internal memory path should look like and therefore thought this is OK.