如何写一个流的内容转换成在.NET中另一个流? [英] How to write the content of one stream into another stream in .net?

查看:108
本文介绍了如何写一个流的内容转换成在.NET中另一个流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常碰到,我有一个流完整的数据,并希望写的这一切都变成另一个流的问题。

I often run into the problem that I have one stream full of data and want to write everything of it into another stream.

所有code-的例子在那里使用一个字节数组形式的缓冲区。

All code-examples out there use a buffer in form of a byte-array.

有没有更优雅的方式吗?

Is there a more elegant way to this?

如果没有,什么是缓冲区的理想尺寸。哪些因素构成了这个值?

If not, what's the ideal size of the buffer. Which factors make up this value?

推荐答案

关于理想的缓冲区大小:

Regarding the ideal buffer size:

当使用Read方法,它是更有效地使用的缓冲区大小相同的流,其中该内部缓冲器被设置到所需的块大小的内部缓冲器,并总是读小于块的大小。如果内部缓冲器的大小为未指定时,流构建,其默认大小为4千字节(4096字节)。

"When using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream, where the internal buffer is set to your desired block size, and to always read less than the block size. If the size of the internal buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes)."

任何流阅读过程中会使用读(字符缓冲区[],INT指数,计数),这是这句话指的是方法。

Any stream-reading process will use Read(char buffer[], int index, count), which is the method this quote refers to.

<一个href="http://msdn.microsoft.com/en-us/library/9kstw824.aspx">http://msdn.microsoft.com/en-us/library/9kstw824.aspx (在备注)。

这篇关于如何写一个流的内容转换成在.NET中另一个流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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