What is the best way to read / write a txt file

What I want to do is read / write a text file as follows:

  • Display the contents of a .txt file in a control, such as RichTextBox
  • Save text in RichTextBox to the specified .txt file

The txt file size will not be large. There are several methods that could do the job, but I'm not sure which one is better.

  • TextReader / TextWriter
  • File class using File.ReadAll, File.WriteAll
+3
source share
3 answers

If you use RichTextBox, the control itself supports, reads, and writes files. - RichTextBox Class

+3
source

It depends on what you mean by "best way." If you mean simplicity, of course, ReadAllText and WriteAllText are the answer. But if you mean performance, then the answer is: "there is no difference in this amount of data."

0
source

All Articles