Reading and Writing Binary Files

You can read and write data to binary files using the BinaryReader and BinaryWriter classes. Both require a FileStream instance and allow reading and writing arrays of bytes. The following is an example of creating a binary stream:

image

The Write method allows writing information as binary but it also accepts base .NET types such as integers and strings, all written as binary. It provides several overloads so that you can also specify the offset and the number of bytes to be written. To read a binary file you instantiate the BinaryReader class. The following example retrieves information from a file utilizing a Using..End ...

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.