这是我的代码(取自stackoverflow)下载,检查并在固定路径上存储图像:
private static void DownloadRemoteImageFile(string uri, string path) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if ((response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect) && response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase)) { using (Stream inputStream = response.GetResponseStream()) using (Stream outputStream = File.OpenWrite(path)) { byte[] buffer = new byte[4096]; int bytesRead; do { bytesRead = inputStream.Read(buffer, 0, buffer.Length); outputStream.Write(buffer, 0, bytesRead); } while (bytesRead != 0); } } }
现在,让我们说,我倒是对双方创建图像path
和path + "\duplicates\";
:什么是最好的方式做到这一点?
回想一下具有不同路径的功能(所以我需要下载两次)或者我可以使用多个outputStream
?
System.Io.File.Copy(path,duplicatePath)