我目前有一个内存流 http://msdn.microsoft.com/en-us/library/System.IO.MemoryStream(v=vs.110).aspx长度约为30000
(Named memStream here
)
我希望这个内存流在chunks
使用以下代码(我在网上找到并进行了一些修改):
byte[] chunk = new byte[4096];
bool hasNext = true;
while(hasNext)
{
int index = 0;
while (index < chunk.Length)
{
int bytesRead = memStream.Read(chunk, index, chunk.Length - index);
if (bytesRead == 0)
{
break;
}
index += bytesRead;
//Do something with this chunk
}
if (index != 0) // Our previous chunk may have been the last one
{
//Do something with the last chunk
}
if (index != chunk.Length) // We didn't read a full chunk: we're done
{
hasNext = false;
}
}
然而以下read()
该方法似乎不起作用
int bytesRead = memStream.Read(chunk, index, chunk.Length - index);
WHERE
chunk: new byte[4096]
index: 0
memstream: capacitiy & length : 34272
memstream: position 0 (according to VS watch)
Always returns
0 bytesRead
Chunk with all values containing '0'
知道为什么吗?这可能是权限许可吗?
感谢您的时间。
创建并填充 MemoryStream 后,您需要将读取位置设置为开头,如下所示:
memStream.Seek(0, SeekOrigin.Begin);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)