0

我正在尝试将字节数组保存到文件中。文件内容未保存到该文件。

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);
    }
}

我在这里错过了什么吗?

4

1 回答 1

1
using (Stream response = lxResponse.GetResponseStream())
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
    response.CopyTo(fs);
}
于 2013-10-16T22:57:24.963 回答