mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 21:44:12 +08:00
27 lines
878 B
C#
27 lines
878 B
C#
namespace detect.device.Utils;
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
public static class FileUtil
|
|
{
|
|
/// <summary>
|
|
/// 下载文件到指定路径
|
|
/// </summary>
|
|
/// <param name="url">文件的 URL</param>
|
|
/// <param name="destinationPath">下载文件的保存路径</param>
|
|
/// <returns>表示异步操作的 Task</returns>
|
|
public static async Task DownloadFileAsync(string url, string destinationPath)
|
|
{
|
|
using HttpClient client = new HttpClient();
|
|
using HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
await using FileStream fs = new FileStream(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None);
|
|
await response.Content.CopyToAsync(fs);
|
|
}
|
|
}
|