Can File.AppendAllText be used with very large files without causing memory issues?

I need to write to a very large text file adding content to it as I interact with a very large set of records in C # 3.5. This file can be several GB in size. I thought I would use File.AppendAllText to write to the file after each write has been processed. This way I do not store the file in memory. However, will AppendAllText read the entire contents of the file into memory when called, or will it just add new content to the end?


source to share

2 answers

Apppending doesn't mean it is loading existing content, so yes, you can use AppendAllText to do this. Note, however, that the StreamWriter can also be used, perhaps more cleanly, to gradually write to the file (plus without having to open / close the file.



From the documentation for File.AppendAllText, it looks like it doesn't read the file in memory.

Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.




All Articles