最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#利用WebClient实现两种方式下载文件
时间:2022-06-25 07:54:58 编辑:袖梨 来源:一聚教程网
最近整理了WebClient 两种方式下载文件 ,留作以后查询。
第一种
| 代码如下 | 复制代码 |
|
stringURLAddress =@"http://xiazai.j*b5**1.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(); | |
相关文章
- 苹果教育优惠入口在哪找-2026苹果教育优惠官网入口直达链接 01-05
- 研招网入口-中国研究生招生信息网官网 01-05
- 中国知网官方入口-权威论文查重与学术资源平台 01-05
- 抖音网页版能抢福袋吗-抖音网页版抢福袋技巧 01-05
- 国家中小学智慧教育平台官网-国家中小学智慧教育平台官网入口 01-05
- 克拉克拉充值官网入口-2026克拉克拉最新官网充值入口 01-05