这是我的C#代码从我的服务器下载ZIP文件。当我下载我没有收到该文件,但它被部分下载。文件没有完全下载
public static void Download(String strURLFileandPath, String strFileSaveFileandPath)
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
byte[] inBuf = new byte[100000];
int bytesToRead = (int)inBuf.Length;
int bytesRead = 0;
while (bytesToRead > 0)
{
int n = str.Read(inBuf, bytesRead, bytesToRead);
if (n == 0)
break;
bytesRead += n;
bytesToRead -= n;
}
try
{
FileStream fstr = new FileStream(strFileSaveFileandPath, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(inBuf, 0, bytesRead);
str.Close();
fstr.Close();
}
catch (Exception e) {
MessageBox.Show(e.Message);
}
}
我的事情的问题在这里
byte[] inBuf = new byte[100000];
发生当我增加byte[] inBuf = new byte[100000];
价值byte[] inBuf = new byte[10000000];
该文件是完全下载。
但我的问题是,如果我下载大于50 MB的文件(例如:200 MB)。
这种方法不好。
谁能告诉我如何解决这个问题?
你的键盘似乎有同样的问题。 :) – leppie 2012-07-27 12:06:47
不要你在他的文件大小,你的下载 – JohnnBlade 2012-07-27 12:09:54