Pages

Wednesday, 15 February 2012

Reading a text file with TextReader

Why can't I remember the syntax for TextReader and TextWriter? They're simple enough. My only excuse is that I only use them about once a year. Or it might be because when I type
TextRead readFile = new
Intellisense abandons me.
TextReader readFile = new StreamReader(@"Book.csv");
string line;
while (true)
{
   line = readFile.ReadLine();
   if (line == null) break;
   // Process the line here
}
readFile.Close();
TextWriter writeFile = new StreamReader("Book.csv");
writeFile.WriteLine("abc");
writeFile.Close();

No comments: