Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. /*
  7.  * Write a program that enters file name along with its full file path
  8.  * (e.g. C:\WINDOWS\win.ini), reads its contents and prints it on the console.
  9.  * Find in MSDN how to use System.IO.File.ReadAllText(…). Be sure to catch all
  10.  * possible exceptions and print user-friendly error messages.
  11.  */
  12. namespace FullFileException
  13. {
  14.     class FullFileException
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             try
  19.             {
  20.                 string path = @"C:\Temp\New.txt";
  21.                 string readText = File.ReadAllText(path);
  22.                 Console.WriteLine(readText);
  23.             }
  24.             catch (ArgumentException ex)
  25.             {
  26.                 Console.WriteLine(ex.Message);
  27.             }
  28.             catch (NotSupportedException ex)
  29.             {
  30.                 Console.WriteLine(ex.Message);
  31.             }      
  32.                                    
  33.             catch (DirectoryNotFoundException ex)
  34.             {
  35.                 Console.WriteLine(ex.Message);
  36.             }
  37.             catch (IOException ex)
  38.             {
  39.                 Console.WriteLine(ex.Message);
  40.             }            
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement