最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#利用WebClient实现两种方式下载文件
时间:2022-06-25 07:54:58 编辑:袖梨 来源:一聚教程网
最近整理了WebClient 两种方式下载文件 ,留作以后查询。
第一种
代码如下 | 复制代码 |
stringURLAddress =@"http://xiazai.jb51.net";
stringreceivePath=@"C:";
client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress)); |
就OK了。
第二种
代码如下 | 复制代码 |
Stream str = client.OpenRead(URLAddress); StreamReader reader =newStreamReader(str); byte[] mbyte =newbyte[1000000]; intallmybyte = (int)mbyte.Length; intstartmbyte = 0;
while(allmybyte > 0) {
intm = str.Read(mbyte, startmbyte, allmybyte); if(m == 0) break;
startmbyte += m; allmybyte -= m; }
reader.Dispose(); str.Dispose();
stringpath = receivePath + System.IO.Path.GetFileName(URLAddress); FileStream fstr =newFileStream(path, FileMode.OpenOrCreate, FileAccess.Write); fstr.Write(mbyte, 0, startmbyte); fstr.Flush(); fstr.Close(); |
相关文章
- 比特币Coinbase溢价回升,但强度仍低于6月峰值——这对BTC意味着什么? 07-12
- 无畏契约源能行动霓虹实战 霓虹实战技巧详解 07-12
- 幻兽帕鲁流沙蛇去哪捕捉 帕鲁流沙蛇抓取方法介绍 07-12
- Web3遊戲《Seraph》代幣閃崩60%!官方緊急宣布回購$SERAPH 07-12
- 幻兽帕鲁滑水蛇怎么获得 帕鲁滑水蛇获取方法 07-12
- 原神玛薇卡恰斯卡队怎么配队 玛薇卡配队大全攻略 07-12