Reading and Writing Text Files

You create text files instantiating the StreamWriter class, which is a specific stream implementation for writing to text files. The following code, that will be explained, provides an example:

image

The constructor provides several overloads; the one used in the code receives the file name to be created—a Boolean value indicated whether the text must be appended if the file already exists and how the text is encoded. WriteLine is a method that writes a string and then puts a line terminator character. When you are done you must close the stream invoking Close. You can also invoke Write to put in just one character. The ...

Get Visual Basic® 2010 Unleashed 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.