PathIO.WriteTextAsync 方法

定義

多載

WriteTextAsync(String, String)

在指定的路徑或統一資源識別項 (URI) ,將文字寫入檔案。

WriteTextAsync(String, String, UnicodeEncoding)

使用指定的字元編碼,在指定的路徑或統一資源識別項 (URI) ,將文字寫入檔案。

WriteTextAsync(String, String)

在指定的路徑或統一資源識別項 (URI) ,將文字寫入檔案。

public:
 static IAsyncAction ^ WriteTextAsync(Platform::String ^ absolutePath, Platform::String ^ contents);
/// [Windows.Foundation.Metadata.Overload("WriteTextAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncAction WriteTextAsync(winrt::hstring const& absolutePath, winrt::hstring const& contents);
[Windows.Foundation.Metadata.Overload("WriteTextAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncAction WriteTextAsync(string absolutePath, string contents);
function writeTextAsync(absolutePath, contents)
Public Shared Function WriteTextAsync (absolutePath As String, contents As String) As IAsyncAction

參數

absolutePath
String

Platform::String

winrt::hstring

寫入文字之檔案的路徑。

contents
String

Platform::String

winrt::hstring

要寫入的文字。

傳回

這個方法完成時不會傳回任何物件或值。

屬性

範例

此範例示範如何使用 [writeTextAsync (absolutePath,內容) 將一些任意文字寫入路徑上的 absoluteFilePath 檔案,如下所示:

Windows.Storage.FileIO.writeTextAsync(absoluteFilePath, "Swift as a shadow").then(function () {
    // Add code to do something after the text is written to the file
});

雖然 writeTextAsync 方法沒有傳回值,但您仍然可以使用完成來宣告函式,並在文字寫入檔案之後執行其他工作,如範例所示。

備註

這個方法會根據位元組順序標記的存在,嘗試自動偵測檔案的編碼方式。 如果無法偵測到編碼,則會使用方法多載中呼叫端所指定的編碼方式。

另請參閱

適用於

WriteTextAsync(String, String, UnicodeEncoding)

使用指定的字元編碼,在指定的路徑或統一資源識別項 (URI) ,將文字寫入檔案。

public:
 static IAsyncAction ^ WriteTextAsync(Platform::String ^ absolutePath, Platform::String ^ contents, UnicodeEncoding encoding);
/// [Windows.Foundation.Metadata.Overload("WriteTextWithEncodingAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncAction WriteTextAsync(winrt::hstring const& absolutePath, winrt::hstring const& contents, UnicodeEncoding const& encoding);
[Windows.Foundation.Metadata.Overload("WriteTextWithEncodingAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncAction WriteTextAsync(string absolutePath, string contents, UnicodeEncoding encoding);
function writeTextAsync(absolutePath, contents, encoding)
Public Shared Function WriteTextAsync (absolutePath As String, contents As String, encoding As UnicodeEncoding) As IAsyncAction

參數

absolutePath
String

Platform::String

winrt::hstring

寫入文字之檔案的路徑。

contents
String

Platform::String

winrt::hstring

要寫入的文字。

encoding
UnicodeEncoding

檔案的字元編碼。

傳回

這個方法完成時不會傳回任何物件或值。

屬性

另請參閱

適用於