Home  >  Article  >  Backend Development  >  How to use C# FileStream class?

How to use C# FileStream class?

WBOY
WBOYforward
2023-09-15 22:41:06625browse

如何使用C# FileStream类?

The FileStream class provides streams for file operations such as reading and writing.

Create an object like this

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

Above we used FileMode.OpenOrCreate to open or create a file (if the file does not exist yet).

The following example shows 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();
   }
}

The above is the detailed content of How to use C# FileStream class?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete