public CopyToAsync ( |
||
destination | ||
bufferSize | int | |
cancellationToken | CancellationToken | |
return | Task |
using System.IO; using System.Threading.Tasks; public async Task CopyFileAsync(string sourceFile, string destinationFile) { using (FileStream sourceStream = new FileStream(sourceFile, FileMode.Open)) { using (FileStream destinationStream = new FileStream(destinationFile, FileMode.Create)) { await sourceStream.CopyToAsync(destinationStream); } } }This code creates two FileStream objects- one for the source file and one for the destination file. The CopyToAsync method is then called on the sourceFileStream, passing the destinationFileStream as the parameter, to copy the contents of the source file to the destination file asynchronously. In terms of packages, the System.IO namespace is part of the .NET Framework Class Library, which is included in all .NET Framework installations. It is also available in .NET Core and .NET Standard.
public CopyToAsync ( |
||
destination | ||
bufferSize | int | |
cancellationToken | CancellationToken | |
return | Task |