Your first version, which puts everything in a StringBuilder and then writes it, will consume most of the memory. If the text is very large, you may have a shortage of memory. It may be faster, but it may also be slower.
The second option will use much less memory (basically, only the StreamWriter buffer) and will work very well. I would recommend this option. It works well - perhaps better than the first method - and does not have the same potential for running out of memory.
You can speed it up significantly by increasing the size of the output buffer. Instead
File.AppendText("filename")
Create a stream with:
const int BufferSize = 65536; // 64 Kilobytes StreamWriter sw = new StreamWriter("filename", true, Encoding.UTF8, BufferSize);
A 64K buffer size gives much better performance than the default 4K buffer size. You can go more, but I found that more than 64K gives minimal performance, and on some systems it can actually slow down performance.
source share