如何使用 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 日

225 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.