Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

re-read file via a BufferedReader  RSS feed

 
glok twen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. i would like to re-read a large file. i have been using a BufferedReader. after i read it once and get a null returned from readline, i'd like to later go back and do it again.

tried to use reader.mark(0) right after instatiating the BufferedReader, then calling reader.reset() but that threw an exception.

do you know how to do this?

thanks,
gt
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it sounds like you are doing what the docs call for, but what exception is being thrown ? I guess you could if(file.markSupported() && file.ready()) before marking, but since you say that the file is working now and you would like to re-read is a a large file, I would like to know what readAheadLimit you are calling mark() with: After reading readAheadLimit characters, attempting to reset the stream may fail. Further, I would try just calling void close() and re-opening the file. Other than that, there may be other ideas available, what is the size of the file that you think is a large file ?
 
glok twen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you -

used mark(0), not fulling understading how it works.

also, the file is 8mb.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you -

used mark(0), not fulling understading how it works.

also, the file is 8mb.


My suggestion is use mark(1024);// try also 4096 and 8192

With a file of eight megabytes, you will in all reason have to close and re-open the file. I suggest a loop for this, probably a nested loop, with
at the end of the outer loop.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!