我正在尝试将字节数组保存到文件中。文件内容未保存到该文件。
HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create("imageurl");
String lsResponse = string.Empty;
using (HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse())
{
using (BinaryReader reader = new BinaryReader(lxResponse.GetResponseStream()))
{
Byte[] lnByte = reader.ReadBytes(1 * 1024 * 1024 * 10);
String path = Application.StartupPath + "\\abc.jpg";
File.WriteAllBytes(path, lnByte);
}
}
我在这里错过了什么吗?
答案 0 :(得分:1)
using (Stream response = lxResponse.GetResponseStream())
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
response.CopyTo(fs);
}