C#利用WebClient 两种方式下载文件
2024-08-27 06:19:50
WebClient client = new WebClient(); 第一种 string URLAddress = @"http://files.cnblogs.com/x4646/tree.zip"; string receivePath=@"C:\"; client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress)); 就OK了。 第二种 Stream str = client.OpenRead(URLAddress);
StreamReader reader = new StreamReader(str);
byte[] mbyte = new byte[];
int allmybyte = (int)mbyte.Length;
int startmbyte = ; while (allmybyte > )
{ int m = str.Read(mbyte, startmbyte, allmybyte);
if (m == )
break; startmbyte += m;
allmybyte -= m;
} reader.Dispose();
str.Dispose(); string path = receivePath + System.IO.Path.GetFileName(URLAddress);
FileStream fstr = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(mbyte, , startmbyte);
fstr.Flush();
fstr.Close();
最新文章
- Dapper学习笔记(2)-链接引用
- 除法取模练习(51nod 1119 &; 1013 )
- JavaScript Patterns 5.6 Static Members
- C#程序
- 《C#编程》课件 - C#基础
- Image对象及其子类BufferedImage
- c语言操作符 “++”另类行为
- 折叠Collapse插件
- Linq无聊练习系列1--where练习
- R 包 安装 卸载 查看版本
- JavaScript(第十二天)【基本包装类型】
- of_alias_get_id 函数与设备树中aliases节点的关系【转】
- 【.net】未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序解决办法
- htop使用详解
- css学习_写法规范、选择器
- python-----多线程、线程池、进程池
- logging 模块 五星知识
- KSOA单据保护表中Clientid解析为mac和ip
- JS的压缩、混淆、加密
- hadoop框架结构介绍