Stream.Write 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
Write(ReadOnlySpan<Byte>) |
在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。 |
Write(Byte[], Int32, Int32) |
在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。 |
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。
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>
記憶體區域。 這個方法會將此區域內容複製到目前的資料流。
備註
CanWrite使用屬性來判斷目前的實例是否支援寫入。 WriteAsync使用方法,以異步方式寫入目前的數據流。
如果寫入作業成功,數據流內的位置會依寫入的位元元組數目前進。 如果發生例外狀況,數據流內的位置會保持不變。
適用於
.NET 9 及其他版本
產品 | 版本 |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Standard | 2.1 |
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。
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[]
位元組陣列。 此方法會從 buffer
複製 count
位元組到目前資料流。
- offset
- Int32
buffer
中以零起始的位元組位移,即開始將位元組複製到目前資料流的位置。
- count
- Int32
寫入目前資料流的位元組數目。
例外狀況
offset
和 count
的總和大於緩衝區長度。
buffer
為 null
。
offset
或 count
為負。
發生 I/O 錯誤,例如找不到指定的檔案。
資料流不支援寫入。
備註
CanWrite使用屬性來判斷目前的實例是否支援寫入。 WriteAsync使用方法,以異步方式寫入目前的數據流。
如果寫入作業成功,數據流內的位置會依寫入的位元元組數目前進。 如果發生例外狀況,數據流內的位置會保持不變。
另請參閱
適用於
.NET 9 及其他版本
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |