Android Question Read and Write randomly from/to Random Access File

SteveTerrell

Active Member
Licensed User
Longtime User
Most of the examples with the raf seem to sequentially read from RandomAccessFiles files using CurrentPosition which is updated on each read.

If I open a previously created file and wish to read or write an object (a Type structure) at some location in the file presumably I do not have to read all of the objects from the start up to the one I want in order to get its position (which would be sequential access rather than random access).

Is it a case of working out the size of the type (in bytes) and then reading from the location set by object index*size of object (possibly getting the size by reading the first object and using the change in currentposition)?

Or is there a size mechanism for Typed objects that I could use?

This process will of course not work with variable length strings in the object but then a true random access file could not handle writing of new variable length objects into the middle of the file anyway.
 
Top