|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
StreamReader how do I move to BOF?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. I believe you have to close and then re-opend the StreamReader. You
shouldn't have to make a new instance though. Show quote "Johnnie Walker" <tregon***@gmail.com> wrote in message news:1161454851.109879.275610@i3g2000cwc.googlegroups.com... > 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. > 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. Show quote > I believe you have to close and then re-opend the StreamReader. You > shouldn't have to make a new instance though. > > > "Johnnie Walker" <tregon***@gmail.com> wrote in message > news:1161454851.109879.275610@i3g2000cwc.googlegroups.com... > > 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. > > "Johnnie Walker" <tregon***@gmail.com> wrote in message Haven't tried this myself, but I think this should work:news:1161454851.109879.275610@i3g2000cwc.googlegroups.com... > 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. StreamReader sr; .... sr.BaseStream.Seek(0, SeekOrigin.Begin); sr.DiscardBufferedData(); .... |
|||||||||||||||||||||||