namespace detect.device.Utils; using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; public static class FileUtil { /// /// 下载文件到指定路径 /// /// 文件的 URL /// 下载文件的保存路径 /// 表示异步操作的 Task 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); } }