aspose file tools*
The moose likes I/O and Streams and the fly likes BufferedReader mark() and reset() help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "BufferedReader mark() and reset() help" Watch "BufferedReader mark() and reset() help" New topic
Author

BufferedReader mark() and reset() help

Joe Smoe
Greenhorn

Joined: Nov 12, 2010
Posts: 1
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

Joined: Sep 20, 2010
Posts: 3646
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BufferedReader mark() and reset() help