把它转换成整数。。。
FileByteStream.Read(buffer, 0, Convert.ToInt32(outputMessage.FileByteStream.Length))
如果您正在读取的数据大小不合理,您可能需要考虑循环将数据读入缓冲区(例如
MSDN docs
):
//s is the stream that I'm working with...
byte[] bytes = new byte[s.Length];
int numBytesToRead = (int) s.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to 10.
int n = s.Read(bytes, numBytesRead, 10);
// The end of the file is reached.
if (n == 0)
{
break;
}
numBytesRead += n;
numBytesToRead -= n;
}
这样就不需要强制转换,如果选择一个相当大的数字读入缓冲区,则只需通过
while
循环一次。