System.IO.Stream.Write Method

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Syntax

public abstract void Write (byte[] buffer, int offset, int count)

Parameters

buffer
An array of bytes. This method copies count bytes from buffer to the current stream.
offset
The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count
The number of bytes to be written to the current stream.

Exceptions

TypeReason
ArgumentException(offset + count ) is greater than the length of buffer.
ArgumentNullException buffer is null.
ArgumentOutOfRangeException offset or count is negative.
System.IO.IOExceptionAn I/O error occurred.
NotSupportedExceptionThe stream does not support writing.
ObjectDisposedExceptionThe stream is closed.

Remarks

Use the Stream.CanWrite property to determine whether the current instance supports writing. Use the Stream.WriteAsync(Byte[], int, int) method to write asynchronously to the current stream.

If the write operation is successful, the position within the stream advances by the number of bytes written. If an exception occurs, the position within the stream remains unchanged.

Requirements

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