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. 此方法會從 buffer 複製 count 位元組到目前資料流。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.

另請參閱

適用於