June 2003
Intermediate to advanced
800 pages
34h 20m
English
You want to read or write data from a binary file.
Use the BinaryReader or BinaryWriter to wrap the underlying FileStream.
The BinaryReader and BinaryWriter classes provide an easy way to work with binary data. The BinaryWriter class provides an overloaded Write method that takes any basic string or number data type, converts it to a set of bytes, and writes it to a file stream. The BinaryReader performs the same task in reverse—you call methods such as ReadString or ReadInt32, and it retrieves the data from the current position in the file stream and converts it to the desired type.
Here’s a simple code snippet that writes data to a binary file, and reads it back.
' Define the sample data. ...
Read now
Unlock full access