C# FileStream FileStream(String, FileMode, FileAccess, FileShare)

Description

FileStream FileStream(String, FileMode, FileAccess, FileShare) Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.

Syntax

FileStream.FileStream(String, FileMode, FileAccess, FileShare) has the following syntax.


public FileStream(
  string path,//from  w w w  .  j av a 2s  .  c o  m
  FileMode mode,
  FileAccess access,
  FileShare share
)

Parameters

FileStream.FileStream(String, FileMode, FileAccess, FileShare) has the following parameters.

  • path - A relative or absolute path for the file that the current FileStream object will encapsulate.
  • mode - A constant that determines how to open or create the file.
  • access - A constant that determines how the file can be accessed by the FileStream object. This gets the CanRead and CanWrite properties of the FileStream object. CanSeek is true if path specifies a disk file.
  • share - A constant that determines how the file will be shared by processes.

Example


using System;//from  ww w . j av a  2s. c om
using System.IO;
public class MainClass{
   public static void Main(){
        FileStream fileStream = new FileStream(
            "Test.dat", FileMode.OpenOrCreate, 
            FileAccess.ReadWrite, FileShare.ReadWrite);
   
   }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter