Javatpoint Logo
Javatpoint Logo

C# FileStream

C# FileStream class provides a stream for file operation. It can be used to perform synchronous and asynchronous read and write operations. By the help of FileStream class, we can easily read and write data into file.

C# FileStream example: writing single byte into file

Let's see the simple example of FileStream class to write single byte of data into file. Here, we are using OpenOrCreate file mode which can be used for read and write operations.

Output:

A

C# FileStream example: writing multiple bytes into file

Let's see another example to write multiple bytes of data into file using loop.

Output:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

C# FileStream example: reading all bytes from file

Let's see the example of FileStream class to read data from the file. Here, ReadByte() method of FileStream class returns single byte. To all read all the bytes, you need to use loop.

Output:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Next TopicC# StreamWriter





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA