StreamReader sr = new StreamReader("text.txt"); try { Console.WriteLine(sr.ReadToEnd()); } catch (Exception ex) { // If there are any problems reading the file, display an error message Console.WriteLine("Error reading file: " + ex.Message); } finally { // Close the StreamReader, whether or not an exception occurred sr.Close(); }