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.
| Parameter | Description |
|---|---|
| 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 also determines the values returned by 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. |
FileStream(String,IO.FileMode)Constructor
Initializes a new instance of the FileStream class with the specified path and creation mode.
| Parameter | Description |
|---|---|
| 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. |
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.
| Parameter | Description |
|---|---|
| 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 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.
| Parameter | Description |
|---|---|
| array | The buffer to read data into. |
| offset | The byte offset in array at which to begin reading. |
| numBytes | The maximum number of bytes to read. |
| userCallback | The method to be called when the asynchronous read operation is completed. |
| stateObject | A 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.)
| Parameter | Description |
|---|---|
| asyncResult | The 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.
| Parameter | Description |
|---|---|
| array | The buffer containing data to write to the stream. |
| offset | The zero-based byte offset in array from which to begin copying bytes to the stream. |
| count | The maximum number of bytes to write. |