An Easy Way To Read From or Write To A File

WriteAllText creates a new file, writes the given string to the file, and then closes the file.

File.WriteAllText (@"C:\Test.txt", DateTime.Now.ToString());

AppendAllText opens a file, appends the given string at the end of the file, and then closes the file. If the file does not exists, this method ceates creates the file.

File.AppendAllText(@"C:\Test.txt", DateTime.Now.ToString());


ReadAllText opens a file, read all text into a string, and then closes the file.

text=File.ReadAllText(@"C:\Test.txt");

Ebook Download
View all
Learn
View all