Επεξεργασία

Κοινή χρήση μέσω


File.WriteAllBytesAsync Method

Definition

Overloads

WriteAllBytesAsync(String, Byte[], CancellationToken)

Asynchronously creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

WriteAllBytesAsync(String, ReadOnlyMemory<Byte>, CancellationToken)

Asynchronously creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

WriteAllBytesAsync(String, Byte[], CancellationToken)

Source:
File.cs
Source:
File.cs
Source:
File.cs

Asynchronously creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static System.Threading.Tasks.Task WriteAllBytesAsync (string path, byte[] bytes, System.Threading.CancellationToken cancellationToken = default);
static member WriteAllBytesAsync : string * byte[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function WriteAllBytesAsync (path As String, bytes As Byte(), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

path
String

The file to write to.

bytes
Byte[]

The bytes to write to the file.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

A task that represents the asynchronous write operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by WriteAllBytes(String, Byte[]).

Applies to

WriteAllBytesAsync(String, ReadOnlyMemory<Byte>, CancellationToken)

Asynchronously creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static System.Threading.Tasks.Task WriteAllBytesAsync (string path, ReadOnlyMemory<byte> bytes, System.Threading.CancellationToken cancellationToken = default);
static member WriteAllBytesAsync : string * ReadOnlyMemory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function WriteAllBytesAsync (path As String, bytes As ReadOnlyMemory(Of Byte), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

path
String

The file to write to.

bytes
ReadOnlyMemory<Byte>

The bytes to write to the file.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

A task that represents the asynchronous write operation.

Exceptions

path is null.

path is empty.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to