I need to write to a very large text file by adding content to it as I interate over a very large set of records in c# 3.5. This file could be several GBs in size. I thought that I would use File.AppendAllText to write to the file after each record is processed. That way I don’t keep the file in memory. However, will the AppendAllText read the entire contents of the file into memory when called or will it just add the new content to the end of it?
Share
Apppending doesn’t mean it loads the existing content, so yes you can use AppendAllText for this. Note, however, that a StreamWriter could also be used, perhaps more cleanly, to write gradually to a file (plus without having to keep open/close the file.