esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

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:

This code sample is only viewable to esus.com members
Login or become a member!


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!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.