解决得到网络流不支持查找的方案

解决思路:

  1. 将获取的网络流转化成内存流
  2. 内存流位置指向0     
  3. 内存流转化成字节流
//获取fileNamePath路径的网络流
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileNamePath);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();

//将网络流写入内存流
MemoryStream memoryStream = new MemoryStream();
const int bufferLength = 1024;
int actual;
byte[] buffer = new byte[bufferLength];
while ((actual = stream.Read(buffer, 0, bufferLength)) > 0)
{
    memoryStream.Write(buffer, 0, actual);
}
memoryStream.Position = 0;

//将内存流转成字节流
byte[] bytes = new byte[memoryStream.Length];
memoryStream.Read(bytes,0,bytes.Length);
memoryStream.Seek(0,SeekOrigin.Begin);


参考链接:https://blog.csdn.net/fengziyun/java/article/details/7414891

上一篇:从内存流中获取子字符串,而无需将整个流转换为字符串


下一篇:使用DataContext和ItemsSource将数据源绑定到ListView上的区别