码迷,mamicode.com
首页 > 其他好文 > 详细

文件流生成文件

时间:2017-01-17 18:28:27      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:bre   nbsp   ons   path   web   length   create   can   anr   

1.
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); WebResponse myResp = myReq.GetResponse(); byte[] b = null; using( Stream stream = myResp.GetResponseStream() ) using( MemoryStream ms = new MemoryStream() ) { int count = 0; do { byte[] buf = new byte[1024]; count = stream.Read(buf, 0, 1024); ms.Write(buf, 0, count); } while(stream.CanRead && count > 0); b = ms.ToArray(); }
2.

using (FileStream fs = new FileStream(filePath, FileMode.Create))
{
fs.Write(b, 0, b.Length);
}

 

http://stackoverflow.com/questions/3434007/error-this-stream-does-not-support-seek-operations-in-c-sharp

 

文件流生成文件

标签:bre   nbsp   ons   path   web   length   create   can   anr   

原文地址:http://www.cnblogs.com/tangjiansheng/p/6293951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!