Hello, I am using StreamReader.ReadLine() to read a text file.
I need a way to move the "pointer" back to the BOF (Beginning of File)
without having to close the object and create a new instance.
Is there any way of doing this? or is there another class within the
framework that will allow me to achieve this?
Any thoughts/ideas would be greatly appreciated
Thanks
JT.
Scott M. - 21 Oct 2006 19:27 GMT
I believe you have to close and then re-opend the StreamReader. You
shouldn't have to make a new instance though.
> Hello, I am using StreamReader.ReadLine() to read a text file.
>
[quoted text clipped - 9 lines]
>
> JT.
Johnnie Walker - 21 Oct 2006 19:49 GMT
Not too sure of how do I re-open the StreamReader....
do you mean this?:
TextReader tr = new StreamReader("c:\\test.txt");
tr.ReadLine() //read line 1
tr.ReadLine() //read line 2
tr.close();
tr = new StreamReader("c:\\test.txt");
tr.ReadLine() //read line 1
If that's what you mean I think I am still creating a new instance
though
Cheers
JT.
> I believe you have to close and then re-opend the StreamReader. You
> shouldn't have to make a new instance though.
[quoted text clipped - 12 lines]
> >
> > JT.
Peter Duniho - 21 Oct 2006 21:10 GMT
> Hello, I am using StreamReader.ReadLine() to read a text file.
>
> I need a way to move the "pointer" back to the BOF (Beginning of File)
> without having to close the object and create a new instance.
Haven't tried this myself, but I think this should work:
StreamReader sr;
...
sr.BaseStream.Seek(0, SeekOrigin.Begin);
sr.DiscardBufferedData();
...