StreamWriter Class in C# with Programming Example

In this chapter you will learn:

  • What is StreamWriter Class?
  • How to write text into a file using StreamWriter Class?
  • Programming Example

What is StreamWriter Class?

StreamWriter Class is more popular in File Handling and it is very helpful in writing text data in file. It is easy to use and provides complete set of constructors and methods to work.

How to write text into a file using StreamWriter Class?

It is very easy to writer data into a text file using StreamWriter Class and most of the beginners prefer to use this class in writing file. You can understand it with the following programming example.

  • Now open D:\csharpfile.txt and you will see data is saved.

    Save Variable data to file

    Several times you need to save variable data in a file. These variable data might be output of your program, log details, exception error etc. In the next programming I will show you how can you save variable data in a file using StreamWriter Class.

    Now open the D:\csharpfile.txt again and you will see the following text in a file.

    Sum of 5 + 10 = 15


    In this chapter you learned StreamWriter Class and the way to use it in programming. The next chapter explains StreamReader Class in C#.

    Leave a Reply

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