private string down(string inUrl,string title)
{
//以字符流的形式下载文件
WebRequest objRequest = System.Net.HttpWebRequest.Create(inUrl);
try
{
BufferedStream buff = new BufferedStream(objRequest.GetResponse().GetResponseStream()); byte[] bytes = new byte[1024];//这里如果是1000或2000时有时得到的文件(大小5-6M左右)出错有时不出错 FileStream fs2 = new FileStream(title, FileMode.Create, FileAccess.Write);
BufferedStream bs2 = new BufferedStream(fs2); while (buff.Read(bytes, 0, bytes.Length) > 0)
{
// buff.Read(bytes, 0, bytes.Length);
int aa = bytes.Length; bs2.Write(bytes, 0, bytes.Length);
bs2.Flush();
} buff.Close();
bs2.Close();
fs2.Close();
}
catch
{
title = "123";
}
return title;
}
{
//以字符流的形式下载文件
WebRequest objRequest = System.Net.HttpWebRequest.Create(inUrl);
try
{
BufferedStream buff = new BufferedStream(objRequest.GetResponse().GetResponseStream()); byte[] bytes = new byte[1024];//这里如果是1000或2000时有时得到的文件(大小5-6M左右)出错有时不出错 FileStream fs2 = new FileStream(title, FileMode.Create, FileAccess.Write);
BufferedStream bs2 = new BufferedStream(fs2); while (buff.Read(bytes, 0, bytes.Length) > 0)
{
// buff.Read(bytes, 0, bytes.Length);
int aa = bytes.Length; bs2.Write(bytes, 0, bytes.Length);
bs2.Flush();
} buff.Close();
bs2.Close();
fs2.Close();
}
catch
{
title = "123";
}
return title;
}
int readByteNum;
while ((readByteNum = buff.Read(bytes, 0, bytes.Length)) > 0)
{ bs2.Write(bytes, 0, readByteNum);
bs2.Flush();
}