C#利用WebClient 两种方式下载文件
2013-04-11 15:51
155 查看
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();
第一种
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 两种方式下载文件
- C#利用WebClient 两种方式下载文件
- C#利用WebClient实现两种方式下载文件
- C#利用WebClient 两种方式下载文件
- C#开发学习笔记:利用WebClient下载文件
- C#文件下载两种方式
- 使用groovy和java两种方式下载文件文件
- c#实现 ftp ;http;共享方式下载文件 并对比本地文件和服务器文件的更新时间 判断性下载
- C# WinForm通过WebClient实现文件上传下载 (附源码) 分类: C#.NET
- 利用http协议下载文件的第一种方式
- C#两种方式获取指定文件夹下所有子目录及文件
- C# WinForm通过WebClient实现文件上传下载 (附源码)
- ArcEngine与C#添加shp文件的两种方式
- 两种方式文件下载
- java 利用FileOutputStream写文件(两种方式)
- C#两种方式获取指定文件夹下所有子目录及文件
- C#实现文件下载的几种方式
- C#的提交表单方式主要有两种WebClient与HttpWebRequest