complete-reference-vb_net_64
complete-reference-vb_net_64
The code writes "I Love VB .NET" to the console. The technique shown here is useful for building Strings
that you can then simply write to a text output stream. The receiver picks up the object and simply writes to
the console or similar device.
Flush
Flush can also be used to write to the output device. But the method clears the writer's buffer in the process.
The following example demonstrates flushing to a StringBuilder object:
sBuilder = strWriter.GetStringBuilder()
'Write a bunch of characters from the array to the StringBuilder.
strWriter.Write(charArray, 0, 15)
strWriter.Flush(charArray, 0, 15)
Console.WriteLine(sBuilder)
Close
The Close method simply shuts down the writer and its underlying stream as follows:
strWriter.Close()
StreamReader/StreamWriter
While derivatives of the Stream class are intended for Byte I/O, the StreamReader and StreamWriter
classes are intended for writing to and reading from a standard text file. The StreamReader and
StreamWriter classes default to UTF−8 encoding unless specified otherwise, instead of defaulting to the
ANSI code page for the current system. UTF−8 handles Unicode characters correctly and provides consistent
results on localized versions of the operating system. See the earlier "Text Encoding" discussion.
Table 15−29 lists the members of the StreamReader class; Table 15−30 lists the members of the
StreamWriter class.
The Read and Write methods read and write the number of characters specified by their Count parameter.
These are to be distinguished from BufferedStream.Read and BufferedStream.Write, which read and write
the number of bytes specified by a count parameter. Use the BufferedStream methods only for reading and
writing an integral number of byte array elements. For example:
548