http://bbs.csdn.net/topics/360163784
string filepath = @"http://ww4.sinaimg.cn/thumbnail/6741e029jw1dfzrlqr07kj.jpg"; Stream stream = WebRequest.Create(filepath).GetResponse().GetResponseStream(); int size = 1024; int read = 0; MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[size]; do { buffer = new byte[size]; read = stream.Read(buffer, 0, size); ms.Write(buffer, 0, read); } while (read > 0); Console.WriteLine(ms.Length.ToString());
或者:
private void CopyStream(Stream instream, Stream outstream) { const int bufferLen = 4096; byte[] buffer = new byte[bufferLen]; int count = 0; while ((count = instream.Read(buffer, 0, bufferLen)) > 0) { outstream.Write(buffer, 0, count); } }
--