15.2. The FileStream Class

A FileStream abstracts the concept of a disk file or an input/output device. Using the FileStream class you can do primitive read/write operations (as shown in Listing 15.1) on a sequence of bytes read from a file. We call these “primitive” operations because they deal with the underlying data in terms of byte arrays. Also, the functionality of the set of methods available on the Stream class and its subclasses is fairly limited.

The System.IO.FileStream class is a close relative of java.io.FileInputStream and java.io.FileOutputStream. By default, the C# FileStream class deals with files in the slower synchronous mode. Listing 15.2 shows how the FileStream class can be used to write text to a file.

Listing 15.2. Using ...

Get .NET for Java Developers: Migrating to C# 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.