C#实现文件流写入磁盘

   /// <summary>
        /// 写文件导到磁盘(异步)
        /// </summary>
        /// <param name="stream">数据流</param>
        /// <param name="path">文件路径</param>
        /// <returns></returns>
        public static async Task WriteFileAsync(Stream stream, string path)
        {
            using FileStream fileStream = new(path, FileMode.Create, FileAccess.Write, FileShare.Write);
            await stream.CopyToAsync(fileStream);
            fileStream.Close();
        }
posted @ 2022-06-30 17:05  码农阿亮  阅读(185)  评论(0编辑  收藏  举报