将 FileStream 中的数据读入通用 Stream [英] Read data in FileStream into a generic Stream

查看:33
本文介绍了将 FileStream 中的数据读入通用 Stream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一个流读入另一个流的最有效方法是什么?在这种情况下,我试图将 Filestream 中的数据读入通用流.我知道我可以做到以下几点:
1. 逐行读取并将数据写入流
2. 读取字节块并写入流
3.等

What's the most efficient way to read a stream into another stream? In this case, I'm trying to read data in a Filestream into a generic stream. I know I could do the following:
1. read line by line and write the data to the stream
2. read chunks of bytes and write to the stream
3. etc

我只是想找到最有效的方法.

I'm just trying to find the most efficient way.

谢谢

推荐答案

Stephen Toub 在他的 MSDN .NET 问题专栏 此处.在这篇文章中,他描述了一个 CopyStream() 方法,该方法从一个输入流复制到另一个流.这听起来与您想要做的非常相似.

Stephen Toub discusses a stream pipeline in his MSDN .NET matters column here. In the article he describes a CopyStream() method that copies from one input stream to another stream. This sounds quite similar to what you're trying to do.

这篇关于将 FileStream 中的数据读入通用 Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆