C# Files
The File class reads and writes files. ReadAllText, WriteAllText, AppendAllText and File.Exists cover most needs. using statements close streams automatically.
Example
string p = Path.Combine(Path.GetTempPath(), "demo.txt");
File.WriteAllText(p, "one\n");
File.AppendAllText(p, "two\n");
foreach (var line in File.ReadAllLines(p)) Console.WriteLine(line);
File.Delete(p);Exercise
Read all text.
File.(path)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.