svetlozar_kirkov

ReadTxt (Exercise)

Oct 9th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace ConsoleTests
  5. {
  6.     class ConsoleTests
  7.     {
  8.         static void Main()
  9.         {
  10.             ReadTxt(Console.ReadLine());            
  11.             Console.ReadKey();
  12.         }
  13.  
  14.         private static void ReadTxt(string filename)
  15.         {
  16.             try
  17.             {
  18.                 using (StreamReader sr = File.OpenText(filename))
  19.                 {
  20.                     string s = sr.ReadToEnd();
  21.                     Console.WriteLine(s);
  22.                 }
  23.             }
  24.             catch (FileNotFoundException notFound)
  25.             {
  26.                 Console.WriteLine(notFound.Message);
  27.             }
  28.             catch (IOException masterError)
  29.             {
  30.                 Console.WriteLine("Error!");
  31.             }
  32.            
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment