SUMMARY

Streams let a program consider a wide variety of data sources in a uniform way. If a subroutine takes a stream as a parameter, it doesn’t need to worry about whether the stream is attached to a string, file, block of memory, or network connection.

Many applications use the StringReader and StringWriter classes to read and write text in strings, and the StreamReader and StreamWriter classes to read and write text in streams (usually files). The Exists, OpenText, CreateText, and AppendText methods are particularly useful for working with StreamReader and StreamWriter objects associated with text files.

The other stream classes are often used at lower levels or as more abstract classes to allow a routine to process different kinds of streams in a uniform way. If you focus on the four classes (StringReader, StringWriter, StreamReader, and StreamWriter), you will quickly learn how to perform the most common stream operations.

Programs often use the StreamReader and StreamWriter classes to read and write files. Chapter 30, “Filesystem Objects,” describes classes that let a Visual Basic application interact with the filesystem in other ways. These classes let a program examine, rename, move, and delete files and directories.

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.