Constructing a FileStream
Use one of the following static methods on the File class to instantiate a FileStream:
using System;
using System.IO;
class Program
{
static void Main()
{
FileStream fs1 = File.OpenRead("readme.bin"); // Read-only FileStream
FileStream fs2 = File.OpenWrite (@"c:\writeme.tmp"); // Write-only FileStream
FileStream fs3 = File.Create (@"c:\writeme.tmp"); // Read/write
}
}
The following opens an existing file for read/write access without overwriting it:
using System;
using System.IO;
class Program
{
static void Main()
{
var fs = new FileStream("readwrite.tmp", FileMode.Open); // Read/write
}
}