Computer >> Máy Tính >  >> Lập trình >> C#

Làm thế nào để sử dụng lớp C # FileStream?

Một luồng cho các hoạt động tệp như đọc và ghi được cung cấp bởi lớp FileStream.

Tạo một đối tượng như thế này

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

Ở trên, chúng tôi đã sử dụng FileMode.OpenOrCreate để tệp hoặc mở hoặc tạo nếu tệp chưa tồn tại.

Sau đây là n ví dụ cho thấy cách sử dụng lớp FileStream trong C # -

using System;
using System.IO;

public class Demo {
   public static void Main(string[] args) {
      FileStream fstream = new FileStream("d:\\new.txt", FileMode.OpenOrCreate);

      // write into the file
      fstream.WriteByte(90);

      // close the file
      fstream.Close();
   }
}