File streaming consists of performing one of the routine
operations on a file, such as creating it or opening it. This basic operation
can be performed using a class called FileStream.
You can use a FileStream object to get a stream ready for
processing. As one of the most complete classes of file processing of the .NET
Framework, FileStream is equipped with all necessary properties and
methods. To use it, you must first declare a variable of it. The class is
equipped with nine constructors.

One of the constructors (the second) of the FileStream
class has the following syntax:

public FileStream(string path, FileMode mode);

This constructor takes as its first argument the name or the
file or its path. The second argument specifies the type of operation to perform
on the file. Here is an example:

A streaming operation is typically used to create a stream.
Once the stream is ready, you can write data to it. The writing operation is
perform through various classes. One of these classes is BinaryWriter.

The BinaryWriter class can be used to write values of
primitive data types (char, int, float, double,
etc). To use a BinaryWriter value, you can first declare its variable. To do
this, you would use one of the class' three constructors. One of its
constructors (the second) has the following syntax:

public BinaryWriter(Stream output);

This constructor takes as argument a Stream value,
which could be a FileStream variable. Here is an example:

Most classes that are used to add values to a stream are
equipped with a method called Write. This is also the case for the BinaryWriter
class. This method takes as argument the value that must be written to the
stream. The method is overloaded so that there is a version for each primitive
data type. Here is an example that adds strings to a newly created file:

When you use a stream, it requests resources from the
operating system and uses them while the stream is available. When you are not
using the stream anymore, you should free the resources and make them available
again to the operating system so that other services can use them. This is done
by closing the stream.

To close a stream, you can can call the Close() method of
the class(es) you were using. Here are examples:

As opposed to writing to a stream, you may want to read
existing data from it. Before doing this, you can first specify your intent to
the streaming class using the FileMode enumerator. This can be done using
the FileStream class as follows:

Once the stream is ready, you can get prepared to read data
from it. To support this, you can use the BinaryReader class. This class
provides two constructors. One of the constructors (the first) has the following
syntax:

public BinaryReader(Stream input);

This constructor takes as argument a Stream value,
which could be a FileStream object. After declaring a FileStream
variable using this constructor, you can read data from it. To do this, you can
call an appropriate method. This class provides an appropriate method for each
primitive data type.

After using the stream, you should close it to reclaim the
resources it was using. This is done by calling the Close() method.