Android Question Moving through a random access file

daveinhull

Active Member
Licensed User
Longtime User
Hi,

This might be a silly question, but how do you move through a random access file, particularly how do you move to the end so that you can add more to it? How do you know if you are at the end as there doesn't appear to be an EOF or an event?

Am I missing something?

Dave
 

eurojam

Well-Known Member
Licensed User
Longtime User
you don't have to care about the position, only about the objects, just use CurrentPosition.
If you want to loop through the RAF you can use:
B4X:
   Do While (RAF.CurrentPosition < RAF.Size )
      Object1 = RAF.ReadObject(RAF.CurrentPosition)
   Loop
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi eurojam,

Thanks, that is sort of what I'd worked out. So I guess each time I want to open my app and append to the file I'll need to read through to the end.
Also, when does RAF.Size get updated? When the file is closed or as things are done to the file?

Thanks
Dave
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi eurojam,

I've looked at the post before, but it doesn't really help understand how to get to the end of the file to append more data. It says that CurrentPosition is set to 0 after initialise, but does it get moved to the end if I try writing more data to the file? Confused?
Code:
raf.Initialize(File.DirRootExternal, "1.dat", False) 'CurrentPosition=0 after initialize
array1=raf.readObject(raf.CurrentPosition)
array2=raf.readObject(raf.CurrentPosition)
 
Upvote 0
Top