Hello!
What is the fastest choice for writing text file from script.
Should I use IO.File.WriteAllText or System.IO.StreamWriter or something else?
Printable View
Hello!
What is the fastest choice for writing text file from script.
Should I use IO.File.WriteAllText or System.IO.StreamWriter or something else?
StreamWriter is my choice
You should use WriteAllText if you have a single string that you want to write to a file. WriteAllText will create the StreamWriter, write the string and then close the file internally. There's no point doing it yourself when it can be done for you with a single line of code. If what you want to write is more complex then it may be worthwhile creating a StreamWriter explicitly but I rarely find the need. WriteAllText, WriteAllLines and AppendAllText are simple and all you need in the vast majority of cases.