|
Java™ by example!
|
|
|
How do mark() and reset() work?
You can use the method mark to mark a position in the inputstream and the method reset to return to that mark. It allows you to read ahead in the inputstream to determine what to do next. The mark method accepts an limit (integer), which denotes the maximum number of bytes that are to be read ahead. If you read more than this limit, you cannot return to this mark. Before you can use the mark and reset, you need to test out whether these operations are supported on the inputstream you're reading off. You can do that with markSupported. The following program reads in a file once and the second half of the file again using the same inputstream. Main.java:
To read-ahead, you can also use the PushBackInputStream.
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|