How to use C# FileStream class?

WBOY
Release: 2023-09-15 22:41:06
forward
669 people have browsed it

如何使用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);
Copy after login

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();
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template