首頁  >  文章  >  後端開發  >  如何使用C# FileStream類別?

如何使用C# FileStream類別?

WBOY
WBOY轉載
2023-09-15 22:41:06625瀏覽

如何使用C# FileStream类?

FileStream類別提供了用於檔案操作(例如讀取和寫入)的流。

建立一個像這樣的物件

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

上面我們使用了 FileMode.OpenOrCreate 來開啟或建立檔案(如果檔案尚不存在)。

以下範例展示如何在 C# 中使用 FileStream 類別 -

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

以上是如何使用C# FileStream類別?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除