To go beyond raw byte sequences when dealing with I/O data, the BCL designers invented the
BinaryWriter classes. Just as
StreamWriter can be constructed by passing in a
Stream object to a constructor, this abstraction simplifies the use of streams by providing additional methods. For example, where
StreamReader concerns itself with the notion of textual data and provides a
ReadLine method, the
BinaryReader class exposes
Read methods for various primitive multibyte data types.
Let’s look at an example, again using binary files:
First of all, notice the use of
using blocks to ensure ...