C# StreamWriter - c# - c# tutorial - c# net
What is StreamWriter Class in C# ?
- 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.
- C# StreamWriter class is used to write characters to a stream in specific encoding.
- It inherits TextWriter class.
- It provides overloaded write() and writeln() methods to write data into file.
stream writer and stream reader
C# StreamWriter
C# StreamWriter example:
- Let's see a simple example of StreamWriter class which writes a single line of data into the file.
C# examples - Output :
stream writer and stream reader
- Now open the file, you will see the text "hello c#" in output.txt file.
output.txt:
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.
- Now open the D:\csharpfile.txt again and you will see the following text in a file.
- Sum of 5 + 10 = 15