This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use mark(int readAheadLimit) and reset() in BufferedReader?  RSS feed

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a BufferedReader that wraps a file. After reading the whole file I want to start all over. How to do this? How to decide the value of readAheadLimit?
BufferedReader br = getBufferedReader();
br.mark(???);
while(br.ready()){
String line= br.readLine();
DoSometing(line);
}
br.reset();
while(br.ready()){
String line = br.readLine();
DoSometingElse(line);
}
Thanks
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be easiest to start over by creating the buffered reader again on the same file. If you use mark/reset, the whole contents of the file will have to be saved in memory, which negates most of the advantages of using Readers.
If you use mark and want to be able to reset to the beginning of the file, use the size of the file. There is a function in the File class to determine this.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve.
It looks like it's not a good idea to use reset().
BTW. I looked at your utilities. There are good stuff.
Bruce
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!