Wczytanie pliku z klawiatury

0

Witam. Mam problem. Chce stworzyć program, który ma na celu wczytanie zawartości pliku tekstowego (do którego ścieżka ma zostać wprowadzona przez użytkownika). Jak to zrobić ?

1
            try
            {
                string path = Console.ReadLine();
                // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader(path))
                {
                    // Read the stream to a string, and write the string to the console.
                    String line = sr.ReadToEnd();
                    Console.WriteLine(line);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();

0
Console.WriteLine(File.ReadAllText(Console.ReadLine()));

1 użytkowników online, w tym zalogowanych: 0, gości: 1