← Interactive API Explorer
Namespace: System.IO

FileStream

Provides a Stream for a file, supporting both synchronous and asynchronous read and write operations.

Properties (1)

long Length
Gets the length in bytes of the stream.
Value: A long value representing the length of the stream in bytes.

Methods (6)

FileStream(String,IO.FileMode,IO.FileAccess,IO.FileShare)Constructor
Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.
ParameterDescription
pathA relative or absolute path for the file that the current FileStream object will encapsulate.
modeA constant that determines how to open or create the file.
accessA constant that determines how the file can be accessed by the FileStream object. This also determines the values returned by the CanRead and CanWrite properties of the FileStream object. CanSeek is true if path specifies a disk file.
shareA constant that determines how the file will be shared by processes.
FileStream(String,IO.FileMode)Constructor
Initializes a new instance of the FileStream class with the specified path and creation mode.
ParameterDescription
pathA relative or absolute path for the file that the current FileStream object will encapsulate.
modeA constant that determines how to open or create the file.
FileStream(String,IO.FileMode,IO.FileAccess)Constructor
Initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.
ParameterDescription
pathA relative or absolute path for the file that the current FileStream object will encapsulate.
modeA constant that determines how to open or create the file.
accessA constant that determines how the file can be accessed by the FileStream object. This also determines the values returned by the CanRead and CanWrite properties of the FileStream object. CanSeek is true if path specifies a disk file.
IAsyncResult BeginRead(Byte[],Int32,Int32,AsyncCallback,Object)
Begins an asynchronous read operation. Consider using CancellationToken) instead.
ParameterDescription
arrayThe buffer to read data into.
offsetThe byte offset in array at which to begin reading.
numBytesThe maximum number of bytes to read.
userCallbackThe method to be called when the asynchronous read operation is completed.
stateObjectA user-provided object that distinguishes this particular asynchronous read request from other requests.
Returns: An object that references the asynchronous read.
int EndRead(IAsyncResult)
Waits for the pending asynchronous read operation to complete. (Consider using CancellationToken) instead.)
ParameterDescription
asyncResultThe reference to the pending asynchronous request to wait for.
Returns: The number of bytes read from the stream, between 0 and the number of bytes you requested. Streams only return 0 at the end of the stream, otherwise, they should block until at least 1 byte is available.
void Write(Byte[],Int32,Int32)
Writes a block of bytes to the file stream.
ParameterDescription
arrayThe buffer containing data to write to the stream.
offsetThe zero-based byte offset in array from which to begin copying bytes to the stream.
countThe maximum number of bytes to write.