• Post Reply Bookmark Topic Watch Topic
  • New Topic

Re-reading a file  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm reading a file using...(try/catch blocks omitted for clarity)


Supposing I have read half the lines in a text file, and I want to start it again at the beginning, can I do this?
I tried bufRead.reset(), but it didn't work.

Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you would really need to close the current reader and then open a new one.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what I do is...

Each time I want to start reading from fresh, but that doesn't work.
It doesn't make sense
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you close the previous reader too? Sometimes that's important.

When "it doesn't work", what happens, exactly?

I note that in the code you've shown the variable line is never declared. Perhaps you should show that, because right now that code doesn't look like it could read anything successfully, even before it's reset. What value does line have the first time you reach the while loop? I think when you removed the try/catch stuff, you may have removed other important details.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I just assumed it wasn't that, but my line variable was static, and so after first read of file, it was coming out as null...

So it started the new read as null, I simply used line=""; to fix it.

Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!