in reply to Deleting all the data after a specific position in a text file.
Once you have opened the file (exclusively, and for read/write access), the operating system will instantly tell you how large it is and will allow you to seek to any position within it ... relative to the beginning, or to the end, or to wherever you are now. The filesystem will also provide the capability to truncate the file, and it’s the only way to accomplish that feat, i.e. truncate.
Get the file size, and if it is longer than 300 bytes (heh...), position 300 bytes from the end and truncate. Mission Accomplished.