Reading a Text File Line by Line


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // create reader & open file
  2. TextReader tr = new StreamReader("SomeFile.txt");
  3.  
  4. string line = "EMPTY LINE";
  5. while ((line = tr.ReadLine()) != null)
  6. {
  7. Console.WriteLine(line);
  8. }
  9.  
  10. // close the stream
  11. tr.Close();

URL: http://msdn.microsoft.com/en-us/library/aa287535%28v=vs.71%29.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.