Harsh Thakur said:
Thanks a lot guys.
Jon, I used the TextReader and it worked.
But, lets assume I don't care about the encoding.
Then don't bother reading from the file at all, and make every
character 'x'. Seriously, that's about as useful - not caring about the
encoding, but still wanting the text data, is like opening "a music
file" and wanting the music out of it, but assuming you don't need to
know whether it's stored in MP3, WMA, WAV etc format. (Or rather, it's
worse - at least those formats tell you *in the file* what format they
are.)
Then I can just typecast the return value of Read() into a
char. Is there a problem with this approach?
Yes. It means you're assuming ISO-8859-1, in fact. Is that definitely
the encoding you want? If so, you might as well just use the
appropriate encoding.
I have another question.
How can I know/change the exact position of the underlying
stream. I tried using StreamReader.BaseStream to seek and
to get the current position. But it is not reliable at all.
It seems to jump in multiples of 1024.
That would be because it will have buffered data.
Is there a reliable way to seek to an exact location.
What location do you want to get to - character, or byte? There may
well be a difference, and it wouldn't be a good idea to seek to half
way through a multi-byte UTF-8 character, for instance. How large is
the file? Could you just read the whole thing and then "seek" to
different parts of the string instead?