Stream.Write 方法

定义

重载

Write(ReadOnlySpan<Byte>)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。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.

Write(Byte[], Int32, Int32)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。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.

Write(ReadOnlySpan<Byte>)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。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.

public:
 virtual void Write(ReadOnlySpan<System::Byte> buffer);
public virtual void Write (ReadOnlySpan<byte> buffer);
abstract member Write : ReadOnlySpan<byte> -> unit
override this.Write : ReadOnlySpan<byte> -> unit
Public Overridable Sub Write (buffer As ReadOnlySpan(Of Byte))

参数

buffer
ReadOnlySpan<Byte>

内存的区域。A region of memory. 此方法将此区域的内容复制到当前流。This method copies the contents of this region to the current stream.

注解

CanWrite使用属性可确定当前实例是否支持写入。Use the CanWrite property to determine whether the current instance supports writing. WriteAsync使用方法异步写入当前流。Use the WriteAsync 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.

Write(Byte[], Int32, Int32)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。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.

public:
 abstract void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public abstract void Write (byte[] buffer, int offset, int count);
abstract member Write : byte[] * int * int -> unit
Public MustOverride Sub Write (buffer As Byte(), offset As Integer, count As Integer)

参数

buffer
Byte[]

字节数组。An array of bytes. 此方法将 count 个字节从 buffer 复制到当前流。This method copies count bytes from buffer to the current stream.

offset
Int32

buffer 中的从零开始的字节偏移量,从此处开始将字节复制到当前流。The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

count
Int32

要写入当前流的字节数。The number of bytes to be written to the current stream.

异常

offsetcount 的总和大于缓冲区长度。The sum of offset and count is greater than the buffer length.

buffernullbuffer is null.

offsetcount 为负数。offset or count is negative.

发生 I/O 错误,例如找不到指定文件。An I/O error occurred, such as the specified file cannot be found.

流不支持写入。The stream does not support writing.

在流关闭后调用 Write(Byte[], Int32, Int32)Write(Byte[], Int32, Int32) was called after the stream was closed.

注解

CanWrite使用属性可确定当前实例是否支持写入。Use the CanWrite property to determine whether the current instance supports writing. WriteAsync使用方法异步写入当前流。Use the WriteAsync 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.

另请参阅

适用于