File class provides the static methods CreateText, AppendText, and OpenText to shortcut the process:
using System;
using System.IO;
using System.Linq;
class Program
{
static void Main()
{
using (TextWriter writer = File.CreateText("test.txt"))
{
writer.WriteLine("Line1");
writer.WriteLine("Line2");
}
using (TextWriter writer = File.AppendText("test.txt"))
writer.WriteLine("Line3");
using (TextReader reader = File.OpenText("test.txt")){
while (reader.Peek() > -1){
Console.WriteLine(reader.ReadLine());
}
}
}
}