C# 为什么FileStream提供FtpWebRequest而不是MemoryStream?
我在这里使用msdn示例: 我将文件流更改为MemoryStream,但它不读取字节 当我将其更改回FileStream时,它工作正常 有线索吗 谢谢C# 为什么FileStream提供FtpWebRequest而不是MemoryStream?,c#,ftpwebrequest,C#,Ftpwebrequest,我在这里使用msdn示例: 我将文件流更改为MemoryStream,但它不读取字节 当我将其更改回FileStream时,它工作正常 有线索吗 谢谢 CompressMemoryStream(); Stream requestStream = _request.EndGetRequestStream(ar); const int bufferLength = 2048; byte[] buffer = new byte[buff
CompressMemoryStream();
Stream requestStream = _request.EndGetRequestStream(ar);
const int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
int count = 0;
int readBytes = 0;
do
{
//MemoryStream _compressedOutStream
//is created/filled by 'CompressMemoryStream()'
readBytes = _compressedOutStream.Read(buffer, 0, bufferLength);
requestStream.Write(buffer, 0, readBytes);
count += readBytes;
}
while (readBytes != 0);
requestStream.Close();
state.Request.BeginGetResponse(
new AsyncCallback(EndGetResponseCallback),
state
);
在循环的第一次迭代中,
readBytes
的值是多少
我的第一个猜测是,你犯了和我经常犯的相同的错误:向流中写入内容,然后忘记在开始从流中读取之前将其倒带到开头。如果是这种情况,那么在第一次(也是唯一一次)循环迭代中,readBytes
将为零,因为您处于流的末尾——没有什么可读取的
在开始阅读之前,请尝试设置
stream.Position=0
。当您读入内存流和文件流时,位置是否有差异?