What is streamreader and streamwriter class in C#?
Loading
What is streamreader and streamwriter class in C#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Oct 16, 2022, 9:07 AM
StreamReader and StreamWriter are found in the System.IO namespace. Both classes are useful when you want to read or write character-based data. Both of these classes deal with Unicode characters. StreamReader derives from the Abstract class "TextReader" and StreamWriter derives from "TextWriter".
C# StreamReader is used to read characters to a stream in a specified encoding. StreamReader.Read method reads the next character or next set of characters from the input stream. StreamReader is inherited from TextReader that provides methods to read a character, block, line, or all content.
The following code example creates a StreamReader and reads a file content one line at a time and displays to the console. If there is an exception, the exception is displayed on the console.
StreamWriter class in C# writes characters to a stream in a specified encoding. StreamWriter.Write() method is responsible for writing text to a stream. StreamWriter class is inherited from TextWriter class that provides methods to write an object to a string, write strings to a file, or to serialize XML.
Note: There are few more method are there to do the same please refer article which written very well by @Mahesh Chand sir.
https://www.c-sharpcorner.com/article/csharp-streamwriter-example/
Toufik El AzzaouiPosted Oct 16, 2022, 8:58 AM
Streams are used as an intermediate level between the application and the file.