File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes mark(i) and reset() 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 "mark(i) and reset()" Watch "mark(i) and reset()" New topic

mark(i) and reset()

Nazmul Bhuiyan

Joined: May 23, 2002
Posts: 17
I have been searching for the topic mark and reset and found no exact answer for this. One solution was to recreate the reader. But what about If I don't want to create a new object?
I just copied this from previously posted by Paul Keohan, posted November 11, 2002
Can any one let us know how to use mark and reset please?
When using the readLine() method of BufferedReader to trace through the lines of a file, how can I 'reset' the file to go back to the beginning? The reset() method requires a 'mark' which is set up with a mark(int readAheadLimit) method. All I want is to return to the start of my file without having to create a new object.
Gayathri Prasad
Ranch Hand

Joined: Jun 25, 2003
Posts: 116
The one strategy which strikes me is..
After you open the InpustStream.. first call the mark method with the size of the InputStream as the readLimit to the mark method. You can calculate the # of bytes by using the available() method. And as ur marking the InputStream before you read the data and after you open the InputStream, when ever u call the reset() method, it would reposition the stream to the point where the mark() method was last called. In our case we called it at the beginning of the InputStream thus invariably the Stream moves to the starting point of the InputStream.
Beginning is half done
I agree. Here's the link:
subject: mark(i) and reset()
It's not a secret anymore!