In c#, StreamReader is a class of System.IO namespace, and it is useful to read characters from byte stream with a specific encoding. The StreamReader class has been derived from TextReader to provide the implementation of members to read a text from the stream. By default, it will use UTF8Encoding unless we specify other encodings.
Now, we will see how to use the StreamReader class in c# to read a text from the file with examples.
Following is the example of reading text from a file using the StreamReader object in c#.
When we execute the above example, it will read text from the “Test.txt” file in D drive and return the result as shown following.
This is how you can use the StreamReader class in c# to read the data from a file in the file system.