這是我下載的代碼(從計算器所),一個固定的路徑上查看和存儲圖像:如何下載並保存兩次圖像?
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
?
您可以簡單地使用多個outputStreams – Jaco
您的目標是雙倍下載數據作爲對數據的雙重檢查,或者您是否願意只下載一次然後在本地複製它? – adv12