How to use C# FileStream class?



A stream for file operations such as read and write is provided by the FileStream class.

Create an object like this

FileStream fstream = new FileStream("d:\
ew.txt", FileMode.OpenOrCreate);

Above we have used FileMode.OpenOrCreate so that the file or opened or created if it does not already exist.

The following is n example showing how to use the FileStream class in C# −

using System;
using System.IO;

public class Demo {
   public static void Main(string[] args) {
      FileStream fstream = new FileStream("d:\
ew.txt", FileMode.OpenOrCreate);       // write into the file       fstream.WriteByte(90);       // close the file       fstream.Close();    } }
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements