SteveTerrell Active Member Licensed User Longtime User Sep 11, 2014 #1 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Sep 11, 2014 #2 You don't need to sequentially access the file. However don't use WriteObject for fixed records. See my answer here: http://www.b4x.com/android/forum/threads/fixed-size-records-in-randomaccessfile.44597/#post-272314 Upvote 0
You don't need to sequentially access the file. However don't use WriteObject for fixed records. See my answer here: http://www.b4x.com/android/forum/threads/fixed-size-records-in-randomaccessfile.44597/#post-272314
SteveTerrell Active Member Licensed User Longtime User Sep 11, 2014 #3 Yes, that seems to work well, thanks again Upvote 0