Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. class Test
  5. {
  6. public static void Main()
  7. {
  8. try
  9. {
  10. // Create an instance of StreamReader to read from a file.
  11. // The using statement also closes the StreamReader.
  12. using (StreamReader sr = new StreamReader("TestFile.txt"))
  13. {
  14. String line;
  15. // Read and display lines from the file until the end of
  16. // the file is reached.
  17. while ((line = sr.ReadLine()) != null)
  18. {
  19. Console.WriteLine(line);
  20. }
  21. }
  22. }
  23. catch (Exception e)
  24. {
  25. // Let the user know what went wrong.
  26. Console.WriteLine("The file could not be read:");
  27. Console.WriteLine(e.Message);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement