0% found this document useful (0 votes)
6 views1 page

complete-reference-vb_net_66

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

complete-reference-vb_net_66

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

BinaryReader/BinaryWriter

Close Closes the current StreamWriter and the underlying stream


Flush Clears all buffers for the current writer and causes any buffered data to be
written to the underlying stream
Write Writes to the stream
WriteLine Writes some data as specified by the overloaded parameters, followed by a
line terminator
StreamWriter defaults to using an instance of the UTF8Encoding object unless specified otherwise. This
instance of UTF8Encoding is constructed such that the Encoding.GetPreamble method returns the Unicode
byte order mark written in UTF−8. The preamble of the encoding is added to a stream when you are not
appending to an existing stream. This means any text file you create with StreamWriter will have three byte
order marks at its beginning. UTF−8 handles all Unicode characters correctly and gives consistent results on
localized versions of the operating system. If we now create a StreamReader class, we can figure out what
we wrote to the StreamWriter with the following code:

Dim sReader As StreamReader = New StreamReader(fStream)


sReader.BaseStream.Seek(0, SeekOrigin.Begin)
For intX = 0 to 25
Console.Write cstr(rReader.Read)
Next intX

BinaryReader/BinaryWriter

The BinaryReader and BinaryWriter classes read and write primitive data types as binary values in a
specific encoding. The primary methods in these classes are Read and Write, which come in a different
flavor for every data type supported in the framework.

XML I/O
The .NET XML namespaces remind me of the Amazon jungle. So vast, so thick, and so chock−full of
functionality that you need a dedicated platoon of experts to decipher themin a book dedicated to the subject
of .NET XML support. Still, two classes in the XML realm belong in our inner circle of I/O support because
they represent the fundamental ability to read and write: XMLTextReader and the XMLTextWriter.

Reading XML Files

The XmlTextReader object provides forward−only, read−only access to a stream of XML data. You can gain
programmatic access to the current node in the text by being able to reference the node on which the reader is
positioned. The reader advances through the data by being able to use any of the read methods and properties
to reflect the value of the current node.

The XmlTextReader class implements the abstract XmlReader, which has been designed to conform to
W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.
XmlTextReader provides us with the functionality listed in Table 15−31.

The XmlTextReader class provides the parsing and tokenizing functionality we need to read XML files. The
XML Document Object Model (DOM) provides great flexibility for loading XML files as documents, but
there is still the need to read XML as a file−based stream and perform basic element manipulation. Since
loading XML via the services of the DOM does require some overhead, loading XML files through the
XmlTextReader is normally faster and more efficient.

550

You might also like