There is a bug in the following code. I encountered a similar bug when I wrote the BALConverter tool: http://www.b4x.com/android/forum/th...e-layouts-files-to-json-and-vice-versa.41623/
We want to write three objects to a file. However we want to be able to skip to the third object directly. So we write the position of the third object at the beginning of the file, this allows us later to read the position and jump to the third object directly.
Note that in most cases it is simpler and easier to use KeyValueStore class.
We want to write three objects to a file. However we want to be able to skip to the third object directly. So we write the position of the third object at the beginning of the file, this allows us later to read the position and jump to the third object directly.
B4X:
Sub WriteToFile (o1 As Object, o2 As Object, o3 As Object)
Dim raf As RandomAccessFile
raf.Initialize(...)
raf.CurrentPosition = 4
raf.WriteObject(o1, True, raf.CurrentPosition)
raf.WriteObject(o2, True, raf.CurrentPosition)
raf.WriteInt(raf.CurrentPosition, 0)
raf.WriteObject(o3, True, raf.CurrentPosition)
raf.Close
End Sub
Note that in most cases it is simpler and easier to use KeyValueStore class.