C# StreamReader Class with Programming Example

StreamReader
In this chapter you will learn:

  • What is StreamReader Class?
  • How to read file using StreamReader Class?
  • Programming Examples and Code

What is StreamReader Class?

StreamReader class allows you to read text files easily. Its implementation is easy and it is widely popular among the programmer. However, there are dozens of way to read text file in C# file handling but StreamReader Class is more popular in list.

Important Points about StreamReader Class

  1. Implements a TextReader that reads characters from a byte stream in a particular encoding.
  2. StreamReader class uses UTF-8 Encoding by defaults.
  3. StreamReader class is designed for character input in a particular encoding.
  4. Use this class for reading standard text file.
  5. By default, it is not thread safe.

How to read file using StreamReader class?

As mentioned above it is very easy to read text file using StreamReader Class. Here I am going to write a program that does following thing:

  1. Write some data on text file using StreamWriter class and
  2. Read those data using StreamReader class.
  • Programming Examples and Code

    Output:

    This tutorial explains how to use StreamReader Class in C# Programming

    Good Luck!
    _

    Summary

    In this chapter you learned StreamReader class with complete programming example. In the next chapter you will learn TextWriter Class in C#.


    Leave a Reply

    Your email address will not be published. Required fields are marked *