What does Filestream.Read return value mean? How to read data in chunks and process it?

后端 未结 4 1118
执念已碎
执念已碎 2020-12-19 23:41

I\'m quite new to C# so please bear with me. I\'m reading (using FileStream) data (fixed size) to small array, process the data and then read again and so on to the end of f

4条回答
  •  渐次进展
    2020-12-20 00:26

    FileStream derives from Stream, and Stream is a very generic class and the description of Read is from that generic class. A stream can also be a network stream for example, and there, data might not be currently available, because it has not been send. For a FileStream you can assume, that you will get three types of return values:

    1. return value == count of bytes to be read (last parameter of Read): You are in the middle of the file
    2. return value < count && return value > 0: You might be at the end of the file or the rest of the stream is just not currently available.
    3. return value == 0: You already read all content. Nothing more to read.

提交回复
热议问题