The following code shows how to use StreamReader and StreamWriter to read from a text file and write to a text file.
//Reading from a text file
System.IO.StreamReader srFile = new System.IO.StreamReader(@"c:\foo.txt");
string str = srFile.ReadToEnd();
srFile.Close();
//Writing to a text file
string lines = "foobar";
System.IO.StreamWriter swFile = new System.IO.StreamWriter(@"c:\bar.txt");
swFile.WriteLine(lines);
swFile.Close();