將其轉換爲int ...
FileByteStream.Read(buffer, 0, Convert.ToInt32(outputMessage.FileByteStream.Length))
這可能是一個int,因爲該操作阻塞,直到它完成閱讀...所以如果你在一個高容量的應用程序的時候,你可能不想在您讀入大型文件時阻止。
如果你正在閱讀的是不是合理規模,你可能要考慮循環的數據讀入緩衝區(例如,從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
循環一次。
+1我只是寫了同樣的帖子... – 2010-08-30 13:34:36
謝謝大家都是冠軍 – Amit 2010-08-30 14:07:52