FileStream

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

    }
}
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.