Reading Last Bytes.

BlitzMax Forums/BlitzMax Beginners Area/Reading Last Bytes.

Thareh(Posted 2007) [#1]
Hi, I think this might have been answered before, but I could not think of any phrase to search for, Anyway.

I want to read the last bytes of a file, Without having to read the first bytes. It's only 128 bytes I want from the end of the file, and skip the rest 4 megabytes before them :P

Hope I make any sense, If anyone have any idea please help me :)

Thanks!


TomToad(Posted 2007) [#2]
First use FileSize() to find the size of the file if it's not already known. Then subtract 127 from that to find the offset you need to seek to. Then after opening the file, use SeekStream() to position the file pointer.
Strict
Local Size:int = FileSize("MyFile.dat")
If Size >= 128
    Local Input:TStream = ReadStream("MyFile.dat")
    SeekStream(Input,Size-127)
    ReadTheInfoFromFile()
    CloseStream Input
End If



Thareh(Posted 2007) [#3]
Oh Great, Thanks alot mate! :)