File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "mark(i) and reset()" Watch "mark(i) and reset()" New topic
Author

mark(i) and reset()

Nazmul Bhuiyan
Greenhorn

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.
ATB,
Gaya3
--------------------------------------------------
Beginning is half done
 
Consider Paul's rocket mass heater.
 
subject: mark(i) and reset()
 
Similar Threads
Stop creating object
how to use mark() of InputStream
resetting a BufferedReader
SPRING query: how to have more than one successview
BufferedReader.reset() - Can it take you to the start of the stream?