DataWriter 類別

定義

將資料寫入輸出資料流程。

public ref class DataWriter sealed : IClosable, IDataWriter
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Storage.Streams.IDataWriterFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DataWriter final : IClosable, IDataWriter
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Activatable(Windows.Storage.Streams.IDataWriterFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class DataWriter final : IClosable, IDataWriter
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Storage.Streams.IDataWriterFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DataWriter : System.IDisposable, IDataWriter
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Storage.Streams.IDataWriterFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class DataWriter : System.IDisposable, IDataWriter
function DataWriter(outputStream)
Public NotInheritable Class DataWriter
Implements IDataWriter, IDisposable
繼承
Object Platform::Object IInspectable DataWriter
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

請參閱 DataReader 主題中的程式碼範例。

備註

DataWriter 物件的實例不支援並行寫入。 如果應用程式同時寫入或中斷連結資料流程與寫入物件呼叫的 DataWriter 實例將會失敗,併發生錯誤HRESULT_FROM_WIN32 (ERROR_INVALID_OPERATION) 。

建構函式

DataWriter()

建立並初始化資料寫入器的新實例。

DataWriter(IOutputStream)

建立資料寫入器的新實例,並將其初始化為輸出資料流程。

屬性

ByteOrder

取得或設定輸出資料流程中資料的位元組順序。

UnicodeEncoding

取得或設定輸出資料流程的 Unicode 字元編碼。

UnstoredBufferLength

取得尚未使用的緩衝區大小。

方法

Close()

關閉目前的資料流程,並釋放系統資源。

DetachBuffer()

卸離與資料寫入器相關聯的緩衝區。

DetachStream()

中斷連結與資料寫入器相關聯的資料流程。

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

FlushAsync()

以非同步方式排清資料。

MeasureString(String)

取得字串的大小。

StoreAsync()

將緩衝區中的資料認可至輸出資料流程。 只有當 DataWriter 正在寫入資料流程時,才應該呼叫這個方法;當基礎存放區是緩衝區時,它將會失敗。

WriteBoolean(Boolean)

將布林值寫入輸出資料流程。

WriteBuffer(IBuffer)

將指定緩衝區的內容寫入輸出資料流程。

WriteBuffer(IBuffer, UInt32, UInt32)

將指定的位元組從緩衝區寫入輸出資料流程。

WriteByte(Byte)

將位元組值寫入輸出資料流程。

WriteBytes(Byte[])

將位元組值的陣列寫入輸出資料流程。

WriteDateTime(DateTime)

將日期和時間值寫入輸出資料流程。

WriteDouble(Double)

將浮點值寫入輸出資料流程。

WriteGuid(Guid)

GUID 值寫入輸出資料流程。

WriteInt16(Int16)

將 16 位整數值寫入輸出資料流程。

WriteInt32(Int32)

將 32 位整數值寫入輸出資料流程。

WriteInt64(Int64)

將 64 位整數值寫入輸出資料流程。

WriteSingle(Single)

將浮點值寫入輸出資料流程。

WriteString(String)

將字串值寫入輸出資料流程。

WriteTimeSpan(TimeSpan)

將時間間隔值寫入輸出資料流程。

WriteUInt16(UInt16)

將 16 位不帶正負號的整數值寫入輸出資料流程。

WriteUInt32(UInt32)

將 32 位不帶正負號的整數值寫入輸出資料流程。

WriteUInt64(UInt64)

將 64 位不帶正負號的整數值寫入輸出資料流程。

適用於

另請參閱