Binary Input and Output with the FileStream Class

FileStream is a commonly used and versatile binary stream class that can be used to read and write individual bytes and blocks of bytes. Because characters are merely encoded bytes, the FileStream class can also be used to stream characters. However, it does not contain the same convenient methods targeted at character streams as do the StreamReader and StreamWriter classes.

The FileStream class can be used to create new files as well as open existing files.

Table 22.5 lists a few of FileStream's class members.

Table 22.5. A Few Selected FileStream Class Members
FileStream class member Description
Close Closes the stream and releases any associated resources
ReadByte Reads one byte from the stream ...

Get C# Primer Plus 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.