Reading text files

Assume I have a simple text file: /Users/garry/Desktop/test.txt.

How would I read the entire contents of that file into a string using C# and RTL?

I’ve been looking at the FileStream documentation but I don’t see a constructor that takes a file path.

With .NET you’d do something like:

StreamReader sr = new StreamReader("`/Users/garry/Desktop/test.txt");
string source = sr.ReadToEnd();

The File Class

File.ReadText and File.ReadLines

2 Likes