คลาส FileStream มีสตรีมสำหรับการดำเนินการไฟล์ เช่น การอ่านและเขียน
สร้างวัตถุแบบนี้
FileStream fstream = new FileStream("d:\\new.txt", FileMode.OpenOrCreate); ด้านบนเราใช้ FileMode.OpenOrCreate เพื่อให้ไฟล์หรือเปิดหรือสร้างขึ้นหากยังไม่มีอยู่
ต่อไปนี้เป็นตัวอย่าง n ที่แสดงวิธีการใช้คลาส FileStream ใน 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();
}
}