These are stream helper classes that make it easier to read and write text data onto an underlying stream. The following table describes the TextReader class’s most useful methods.
Method | Purpose |
---|---|
Close | Closes the reader and releases any resources that it is using. |
Peek | Reads the next character from the text without changing the reader’s state so other methods can read the character later. |
Read | Reads data from the input. Overloaded versions of this method read a single character, or an array of characters up to a specified length. |
ReadBlock | Reads data from the input into an array of characters. |
ReadLine | Reads a line of characters from the input and returns the data in a string. |
ReadToEnd | Reads any remaining characters in the input and returns them in a string. |
The following table describes the TextWriter class’s most useful properties.
Property | Purpose |
---|---|
Encoding | Specifies the data’s encoding (ASCII, UTF-8, Unicode, and so forth). |
FormatProvider | Returns an object that controls formatting. |
NewLine | Gets or sets the stream’s new-line sequence. |
The following table describes the TextWriter class’s most useful methods.
Method | Purpose |
---|---|
Close | Closes the writer and releases any resources it uses. |
Flush | Writes any buffered data into the underlying output. |
Write | Writes a value into the output. This method has many overloaded versions that write characters, arrays of characters, integers, strings, unsigned 64-bit integers, and so forth. |
WriteLine | Writes data into the output followed by the new-line sequence. |