TEXTREADER AND TEXTWRITER

Like the BinaryReader and BinaryWriter classes, the TextReader and TextWriter classes are not stream classes, but they provide properties and methods for working with text, which is stream-related. TextReader and TextWriter are abstract (MustInherit) classes that define behaviors for derived classes that read or write text characters. For example, the StringWriter and StreamWriter classes derived from TextWriter let a program write characters into a string or stream, respectively. Normally, you would use these derived classes to read and write text, but you might want to use the TextReader or TextWriter classes to manipulate the underlying classes more generically. You may also encounter a method that requires a TextReader or TextWriter object as a parameter. In that case, you could pass the method either a StringReader/StringWriter or a StreamReader/StreamWriter. For more information on these classes, see the sections “StringReader and StringWriter” and “StreamReader and StreamWriter” later in this chapter.

The following table describes the TextReader object’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 input 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 ...

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.