string fileName = "test.txt"; string textToAdd = "Hello World!"; using (FileStream fs = new FileStream(fileName, FileMode.Append)) { using (StreamWriter writer = new StreamWriter(fs)) { writer.WriteLine(textToAdd); } }
string fileName = "test.txt"; using (FileStream fs = new FileStream(fileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(fs)) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } } }This example opens a file called "test.txt" with the Open mode of the FileMode enumeration, and reads all the lines in the file using StreamReader. Each line is then output to the console. Package library: This class is part of the .NET Framework library, which is a standard library for C# and other .NET languages. No external package or library is required for using this class.