This is a beta version of an important new feature.
Two new methods were added to RandomAccessFile: WriteObject and ReadObject.
These methods allow you to write and read objects to files easily.
The following types of objects are supported: lists, maps, arrays, strings, primitive types (numeric types) and user defined types.
Combinations of these types are also supported.
Unlike File.ReadMap or ReadList which convert the data to string, here the data type is kept. This means that the file is not a text file. It is a binary file.
Another new field was added named CurrentPosition. This field holds the current file position. It advances automatically after each read or write.
For example, writing an array to a file:
Installation instructions:
- Unzip the attached file.
- Copy both files to the internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries
Two new methods were added to RandomAccessFile: WriteObject and ReadObject.
These methods allow you to write and read objects to files easily.
The following types of objects are supported: lists, maps, arrays, strings, primitive types (numeric types) and user defined types.
Combinations of these types are also supported.
Unlike File.ReadMap or ReadList which convert the data to string, here the data type is kept. This means that the file is not a text file. It is a binary file.
Another new field was added named CurrentPosition. This field holds the current file position. It advances automatically after each read or write.
For example, writing an array to a file:
B4X:
Dim raf As RandomAccessFile
raf.Initialize(File.DirRootExternal, "1.dat", False)
Dim arr(10) As Int
'fill the array...
raf.WriteObject(arr, True, raf.CurrentPosition)
raf.Close
- Unzip the attached file.
- Copy both files to the internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries