Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- /*
- * Write a program that enters file name along with its full file path
- * (e.g. C:\WINDOWS\win.ini), reads its contents and prints it on the console.
- * Find in MSDN how to use System.IO.File.ReadAllText(…). Be sure to catch all
- * possible exceptions and print user-friendly error messages.
- */
- namespace FullFileException
- {
- class FullFileException
- {
- static void Main(string[] args)
- {
- try
- {
- string path = @"C:\Temp\New.txt";
- string readText = File.ReadAllText(path);
- Console.WriteLine(readText);
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (NotSupportedException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (DirectoryNotFoundException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (IOException ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement