File I/O is nowhere near that wasteful. The reader classes might do some
caching, to do fewer block reads.
They do, at least some of them. For example, StreamReader.
Seeking to the appropriate position
should cause the reader to flush its cache, if any.
This is not true. If the data at the position being seeked to has already
been buffered, the cache isn't flushed. That's why StreamReader has the
DiscardBufferedData() method. You can't rely on seeking to update the
reader's buffers for you.
Actually the reader might not support seeking,
Actually, I'm not aware of any reader that does support seeking
explicitly. For example, for StreamReader you need to use the seeking
mechanisms on the base stream. This is one of the reasons that the reader
itself doesn't flush its buffers automatically...it has no practical way
to know that it needs to do that.
only the underlying file, so you would have to
close the reader, seek the file, and create a new reader.
I'm not aware of any file-based streams that don't support seeking.
However, yes...if you have a different kind of reader that is based on a
stream that doesn't support seeking (for example, a StringReader, or a
StreamReader that's using a NetworkStream), you can't seek.
If you need a
reader at all, that is, FileStream might be enough.
I find it useful to use a StreamReader when I know that my FileStream is
from a text file. No, it's not strictly required, but then none of the
reader classes are. But yes, if you want to seek a reader, you have to
use the underlying i/o class to do that, assuming it's possible at all.
The one concern I might have regarding all this is the behavior of the
stream and/or reader class upon reaching the end of the stream. For
example, for sure a NetworkStream is simply unusable once you've read to
the end of the stream; the network connection is closed.
Obviously this doesn't specifically apply to file-based streams, but the
OP should definitely double-check to make sure that once he's reached the
end of the stream, the stream and/or reader class doesn't just set some
internal state and never return any more data from beyond that point. I
would _guess_ that it wouldn't do that, but since I haven't done this
specifically, I don't want to say for sure that it's okay.
Pete