/// <summary> /// 根据网络路径把文件保存成byte[],保存到本地 /// </summary> /// <param name="zjkurl"></param> public void UrlToByte(string zjkurl) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(zjkurl); req.Method = "GET"; using (WebResponse wr = req.GetResponse()) { StreamReader responseStream = new StreamReader(wr.GetResponseStream(), Encoding.UTF8); int length = (int)wr.ContentLength; byte[] bs = new byte[length]; HttpWebResponse response = wr as HttpWebResponse; Stream stream = response.GetResponseStream(); //读取到内存 MemoryStream stmMemory = new MemoryStream(); byte[] buffer1 = new byte[length]; int i; while ((i = stream.Read(buffer1, 0, buffer1.Length)) > 0) { stmMemory.Write(buffer1, 0, i); } byte[] arraryByte = stmMemory.ToArray(); stmMemory.Close(); //保存到本地 string path = Server.MapPath(@"a.jpg"); FileStream fs = new FileStream(path, FileMode.Create); fs.Write(arraryByte, 0, arraryByte.Length); fs.Dispose(); } }