18.3. Reading from or writing to a binary file

You can use the FileStream class for reading from or writing to a binary file.

18.3.1. Creating a FileStream object

You create an instance of a FileStream object by passing in the path to the file you want to read. The FileStream class has several overloaded constructors which you can use to specify the following options:

  • file mode

  • file access

  • file share.

Table 18.5 describes these options.

Table 18.5. The available file mode, access, and share options that can be used when instantiating a FileStream
EnumerationDescription
FileMode – how to open or create this file?
FileMode.AppendOpens a file, if it exists, for appending. Moves the file pointer to the end of the existing file, so that the original data ...

Get From Java to C#: A Developer's Guide 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.