Example

 using System; using System.IO; namespace Samples { public class FileAccessSample { public static void Main() { string s = @"FileAccess.txt"; FileAccess[] fa = {FileAccess.Read, FileAccess.ReadWrite, FileAccess.Write }; foreach(FileAccess a in fa) { using(FileStream fs = File.Open(s, FileMode.OpenOrCreate, a)) { Display(fs, s, a); Console.WriteLine(); } } } private static void Display(FileStream fs, string s, FileAccess a) { Console.WriteLine( "Can read from {0} when opened with {1}: {2}", s, a, fs.CanRead); Console.WriteLine( "Can write to {0} when opened with {1}: {2}", s, a, fs.CanWrite); Console.WriteLine( "Can seek in {0} when opened with {1}: {2}", s, a, fs.CanSeek); Console.WriteLine( "Async access to {0} when opened with {1}: ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.