如何使用 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();
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP