• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader mark() and reset() help

 
Joe Smoe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to write a function that grabs a 4 character sequences of a file, sends that to another function, then continue to do the same thing from where the BufferedReader left off until the end of the file but can't seem to figure out how to make it work. Here is what I have so far:



Any help as to what I'm doing wrong is much appreciated.

 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a few problems. First of all, you don't need mark and reset. They are used to reread the same parts of a file.

Secondly, after you read your first sequence, the program will stop reading, because count is always 4. You don't reset it.

Thirdly, what happens when the file has less than 4 characters left at some point, but more than one? It will cast -1 to a character and append it to str. This will result in the last unicode character in existence.

Lastly, you might want to consider using a StringBuilder instead of a String. With a large file, the overhead of appending single characters to the end of a String may be very big.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic