C#利用WebClient 两种方式下载文件
来源:互联网 发布:易吧进销存软件网络版 编辑:程序博客网 时间:2024/05/21 22:27
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[1000000];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (allmybyte > 0)
{
int m = str.Read(mbyte, startmbyte, allmybyte);
if (m == 0)
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, 0, startmbyte);
fstr.Flush();
fstr.Close();
- C#利用WebClient 两种方式下载文件
- C#下载文件:WebClient
- C#开发学习笔记:利用WebClient下载文件
- 利用WebClient异步下载文件
- C# 文件下载(WebClient)
- 使用WebClient上传文件的两种方式
- C#中使用WebClient对象下载文件
- c# WebClient.DownloadFile文件下载方法
- 两种方式文件下载
- c# webclient下载网页
- 利用WebClient上传文件
- WebClient下载文件代码!
- WebClient下载文件
- WebClient异步下载文件
- webclient下载文件
- C#使用WebClient下载文件到本地目录
- 文件下载的两种方式
- Spring MVC - 两种文件下载方式
- Android Zxing实现二维码扫描功能
- java.util.Set<E>
- linux下的find文件查找命令与grep文件内容查找命令
- SOLID原则
- C# Hook鼠标消息
- C#利用WebClient 两种方式下载文件
- 向量,四元数理解。
- QT 串口通讯
- java调用动态链接库 dll
- QT *char 转QString
- 主键的选择
- zstack linux gateway 移植
- 代码审查--CodeReview
- chmod u+x file.sh这句中chmod、u、x、+、a、o、g分别代表什么呢