Non-sequential Read/Writes

BlitzMax Forums/BlitzMax Beginners Area/Non-sequential Read/Writes

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ReadString, WriteString etc all use the streams current position to determine where to read or write.

Use SeekStream and StreamPos to set or determine position and then read or write as you see fit.

Strict

CreateFile("c:\testout.txt") 'openstream requires a file exists before you can use it.

Local myStream:TStream = OpenStream("c:\testout.txt")

If Not myStream Then RuntimeError("Error creating c:\testout.txt")

WriteString(myStream, "This is a test")
Print StreamPos(myStream)

SeekStream(myStream, 0)
Print ReadString(myStream, StreamSize(myStream))

SeekStream(myStream, 10)
WriteString(myStream, "Mongoose")
Print StreamPos(myStream)
SeekStream(myStream, 0)
Print ReadString(myStream, StreamSize(myStream))

CloseStream(myStream)