java.io.BufferedReader mark(int readAheadLimit)

Description :

This java tutorial shows how to use the mark() method of BufferedReader class of java.io package. This method returns void and mark the present position in the stream. Make a note that a subsequent call to reset() will attempt to re position the stream to this point. This method overrides the mark() method of Reader class.

Method Syntax :

public void mark(int readAheadLimit) throws IOException

Parameter Input :

DataType Parameter Description
int readAheadLimit this parameter input is the limit on the number of characters that may be read but preserving the current mark.

Method Returns :

This method returns void but mark the present position on the stream.

Compatibility Version :

Requires Java 1.1 and up

Exception :

IllegalArgumentException

– this exception will be thrown if the readAheadLimit is negative number or less than 0

IOException

– the IOException will be thrown my mark() method if I/O error occurs.

Java Code Example :

This java example source code demonstrates the use of mark() method of BufferedReader class. Basically we mark the stream and use the reset method to go back to the marked index.

Sample Output :

Running the mark() method example source code of BufferedReader class will give you the following output

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :