System.IO.FileStream.Write Method

Writes a block of bytes to the file stream.

Syntax

public override void Write (byte[] array, int offset, int count)

Parameters

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.

Exceptions

TypeReason
ArgumentNullException array is null.
ArgumentException offset + count is greater than the length of array.
ArgumentOutOfRangeException offset or count is negative.
System.IO.IOExceptionAn I/O error occurred.
NotSupportedExceptionThe current stream does not support writing.
ObjectDisposedExceptionAn I/O error occurred.

Remarks

This method overrides Stream.Write(Byte[], int, int).

The offset parameter gives the offset of the byte in array (the buffer index) at which to begin copying, and the count parameter gives the number of bytes that will be written to the stream. If the write operation is successful, the current position of the stream is advanced by the number of bytes written. If an exception occurs, the current position of the stream is unchanged.

Note:

Use the FileStream.CanWrite property to determine whether the current instance supports writing. For additional information, see Stream.CanWrite.

Do not interrupt a thread that is performing a write operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.

For a list of common file and directory operations, see Common I/O Tasks.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0