473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Resetting IO.StreamReader to beginning of file

I am using an IO.StreamReader to read the contents of a text file. It
all works just fine. However, I do not know of a way to move back to
the beginning of a file. For example, let's say that I read in five
lines from the file, or all of them for that matter. How do I then
point the IO.StreamReader back to the beginning of the file? I would
imagine that I could use "New IO.StreamReader(sFileName)" to create a
new IO.StreamReader pointing to the file, and starting back from the
beginning. I am just wondering if there is another way to do this
(i.e. some method or something).
Jan 7 '08 #1
2 5061
I think you want to use a FileStream, which supports the Seek() method. You
can pass the FileStream to the constructor for the StreamReader if you need
methods in the StreamReader.

"BobRoyAce" wrote:
I am using an IO.StreamReader to read the contents of a text file. It
all works just fine. However, I do not know of a way to move back to
the beginning of a file. For example, let's say that I read in five
lines from the file, or all of them for that matter. How do I then
point the IO.StreamReader back to the beginning of the file? I would
imagine that I could use "New IO.StreamReader(sFileName)" to create a
new IO.StreamReader pointing to the file, and starting back from the
beginning. I am just wondering if there is another way to do this
(i.e. some method or something).
Jan 8 '08 #2
Strange.

Changing the position of the cursor in the underlying stream doesn't work!

StreamReader must keep its own cursor position or something.

--
David Streeter
Synchrotech Software
Sydney Australia
"Family Tree Mike" wrote:
I think you want to use a FileStream, which supports the Seek() method. You
can pass the FileStream to the constructor for the StreamReader if you need
methods in the StreamReader.

"BobRoyAce" wrote:
I am using an IO.StreamReader to read the contents of a text file. It
all works just fine. However, I do not know of a way to move back to
the beginning of a file. For example, let's say that I read in five
lines from the file, or all of them for that matter. How do I then
point the IO.StreamReader back to the beginning of the file? I would
imagine that I could use "New IO.StreamReader(sFileName)" to create a
new IO.StreamReader pointing to the file, and starting back from the
beginning. I am just wondering if there is another way to do this
(i.e. some method or something).
Jan 14 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
OK I am half way there - I can manipulate the stream without the byte issue like this - but is this the way to push the new values back into the stream & write out the stream without resorting to...
9
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
1
by: Tarren | last post by:
Hi: Question which might have something to do with encoding? I have a text file and I use the following code to iterate through. StreamReader oStreamFile = new StreamReader(sFileName); ...
31
by: J.S. | last post by:
Let's say I have a text file with parameters like the following embedded in the text: @@Textbox1@@, @@Textbox2@@, etc. Is it possible to replace the parameters in the text file with values...
1
by: Dennis | last post by:
I want to have my program look on the CD drive for the data files needed to run my program but I can't find any info on this. I am using a StreamReader to get really simple information from a text...
5
by: jkristia | last post by:
StreamReader throws an exception if I attempt to open a .csv file which is also opened by Excel. I checked this list and found what I though was the solution, first open the file stream in read...
3
by: Davidhere40 | last post by:
I'm trying to lock a text file, read its contents, make the text file empty, then unlock it. I haven't been successful at it yet. The following code is what I've tried, with no success, because...
2
by: Quentin | last post by:
I am currently working with a text file and cannot seem to get it to filter right. I am trying to delete every line above a keyword "Recipe" and every line below a keyword. Or just move every...
3
by: Tom | last post by:
I don't want to re-invent the wheel and am looking for a simple implementation of a text viewer or RichTextBox in read only mode that allows rapid file positioning within large data files without...
1
by: PSiegmann | last post by:
Hello group, if I open with streamreader a file to read in that way: StreamReader sr = new StreamReader(c:\\test.txt, System.Text.Encoding.GetEncoding(10000)); Is it possible that it can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.