如何使用 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();    } }

更新時間:2020 年 6 月 20 日

224 瀏覽

開啟你的職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.