File.AppendAllBytesAsync Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

AppendAllBytesAsync(String, Byte[], CancellationToken)

Asynchronously appends the specified byte array to the end of the file at the given path.

If the file doesn't exist, this method creates a new file. If the operation is canceled, the task will return in a canceled state.

AppendAllBytesAsync(String, ReadOnlyMemory<Byte>, CancellationToken)

Asynchronously appends the specified byte array to the end of the file at the given path.

If the file doesn't exist, this method creates a new file. If the operation is canceled, the task will return in a canceled state.

AppendAllBytesAsync(String, Byte[], CancellationToken)

Source:
File.cs

Asynchronously appends the specified byte array to the end of the file at the given path.

If the file doesn't exist, this method creates a new file. If the operation is canceled, the task will return in a canceled state.

C#
public static System.Threading.Tasks.Task AppendAllBytesAsync(string path, byte[] bytes, System.Threading.CancellationToken cancellationToken = default);

Parameters

path
String

The file to append to.

bytes
Byte[]

The bytes to append to the file.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous append operation.

Exceptions

path or bytes is null.

path is empty.

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

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

AppendAllBytesAsync(String, ReadOnlyMemory<Byte>, CancellationToken)

Asynchronously appends the specified byte array to the end of the file at the given path.

If the file doesn't exist, this method creates a new file. If the operation is canceled, the task will return in a canceled state.

C#
public static System.Threading.Tasks.Task AppendAllBytesAsync(string path, ReadOnlyMemory<byte> bytes, System.Threading.CancellationToken cancellationToken = default);

Parameters

path
String

The file to append to.

bytes
ReadOnlyMemory<Byte>

The bytes to append to the file.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous append operation.

Exceptions

path is null.

path is empty.

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

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10