File.WriteAllLinesAsync 方法

定义

重载

WriteAllLinesAsync(String, IEnumerable<String>, CancellationToken)

以异步形式创建一个新文件,在其中写入指定的行,然后关闭该文件。Asynchronously creates a new file, writes the specified lines to the file, and then closes the file.

WriteAllLinesAsync(String, IEnumerable<String>, Encoding, CancellationToken)

以异步形式创建一个新文件,使用指定编码在其中写入指定的行,然后关闭该文件。Asynchronously creates a new file, write the specified lines to the file by using the specified encoding, and then closes the file.

WriteAllLinesAsync(String, IEnumerable<String>, CancellationToken)

以异步形式创建一个新文件,在其中写入指定的行,然后关闭该文件。Asynchronously creates a new file, writes the specified lines to the file, and then closes the file.

public static System.Threading.Tasks.Task WriteAllLinesAsync (string path, System.Collections.Generic.IEnumerable<string> contents, System.Threading.CancellationToken cancellationToken = default);
static member WriteAllLinesAsync : string * seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function WriteAllLinesAsync (path As String, contents As IEnumerable(Of String), Optional cancellationToken As CancellationToken = Nothing) As Task

参数

path
String

要写入的文件。The file to write to.

contents
IEnumerable<String>

要写入到文件中的行。The lines to write to the file.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

Task

表示异步写入操作的任务。A task that represents the asynchronous write operation.

适用于

WriteAllLinesAsync(String, IEnumerable<String>, Encoding, CancellationToken)

以异步形式创建一个新文件,使用指定编码在其中写入指定的行,然后关闭该文件。Asynchronously creates a new file, write the specified lines to the file by using the specified encoding, and then closes the file.

public static System.Threading.Tasks.Task WriteAllLinesAsync (string path, System.Collections.Generic.IEnumerable<string> contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default);
static member WriteAllLinesAsync : string * seq<string> * System.Text.Encoding * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function WriteAllLinesAsync (path As String, contents As IEnumerable(Of String), encoding As Encoding, Optional cancellationToken As CancellationToken = Nothing) As Task

参数

path
String

要写入的文件。The file to write to.

contents
IEnumerable<String>

要写入到文件中的行。The lines to write to the file.

encoding
Encoding

要使用的字符编码。The character encoding to use.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

Task

表示异步写入操作的任务。A task that represents the asynchronous write operation.

适用于