C# reading from and write to text file

CSharp sample for reading from a text file and writing 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();

Comments

Leave a Reply