To open an existing file for read or to write a new file out, you need to instantiate a TFileStream.
The TFileStream constructor takes three parameters:
TFileStream instances keep track of the end of file, also called end of stream. As you write out a file stream, the end-of-file marker moves forward. If you want to increase your efficiency, you can use TFileStream:SetLogicalEndOfStream to move the marker forward to the position you want.
NOTE When you move the end-of-file marker forward, the results you get depend on the host file system. Some file systems use more disk space to extend the file to match the new logical end-of-file marker. Other file systems do not change the end-of-file position until you write the file out. Still other file systems only allow you to allocate a portion of disk space as you use it, regardless of the logical end-of-stream location. Because your code might be used on different file systems, you need to code as though you risk running out of file space each time you move the end-of-file marker.
This example:
TStandardText fileName("MyFile"); TFile theFile = homeDirectory.CreateFile(fileName); TFileStream theFileStream(theFile); fileContents >>= theFileStream; FileSystemEntitySize length = theFileStream.GetEndOfFile(); int amount = length.GetLeastSignificant(); qprintf("Streaming out completed. File length: %d\n", amount);
TFileStream aFileStream(theFile); fileContents <<= aFileStream;