Create FileStream from FileInfo with file mode, file access and file sharing : File Access Mode « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;

public class MainClass
{
  static void Main(string[] args)
  {

    FileInfo MyFiles = new FileInfo(@"c:\Testing.txt");
    FileStream MyFileStream1 = MyFiles.Open(FileMode.Append, FileAccess.Read, FileShare.None);

    int MyBytes = MyFileStream1.ReadByte();

    MyFileStream1.Close();    
  }
}








15.9.File Access Mode
15.9.1.FileStream is opened for FileAccess.ReadWrite (default) and FileShare.None (default)
15.9.2.FileStream is opened for FileAccess.Write FileShare.None (default) and is positioned at the end (because of FileMode.Append)
15.9.3.FileStream is opened for FileAccess.ReadWrite FileShare.Read and has had its entire contents truncated (due to FileMode.Truncate)
15.9.4.Use FileStream with StreamWriter to provide a greater degree of control in how you open the file
15.9.5.Creates a file with read-write access that allows others to read
15.9.6.Create FileStream from FileInfo with file mode, file access and file sharing