Advertisement
Martichka

Exception Handling/ Task - 3 Reading Text file

Jan 27th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. class ReadATextAndPrintIt
  5. {
  6.     public static void Main()
  7.     {
  8.         try
  9.         {
  10.             Console.WriteLine("Enter the full path to file you want to write on console:");
  11.             string path = Console.ReadLine();
  12.             string readText = File.ReadAllText(path);
  13.             Console.WriteLine(readText);
  14.         }
  15.         catch (ArgumentException)
  16.         {
  17.             Console.WriteLine("Wrong path is entered.");
  18.         }
  19.         catch (DirectoryNotFoundException)
  20.         {
  21.             Console.WriteLine("Can't find the file directory.");
  22.         }
  23.         catch (IOException)
  24.         {
  25.             Console.WriteLine("Problem occures while opening file. Or file is not found.");
  26.         }
  27.         catch (UnauthorizedAccessException)
  28.         {
  29.             Console.WriteLine("You have no permision to open the file or a directory.");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement