java.io.BufferedReader skip()

Description :

This java tutorial shows how to use the skip() method of BufferedReader class of java.io package. This method returns how many characters has been skipped. This method override the skip() method of Reader Class.

Method Syntax :

public long skip(long n) throws IOException

Parameter Input :

DataType Parameter Description
long n It corresponds to the number of characters to skip

Method Returns :

This method simply returns how many characters were skipped.

Compatibility Version :

Requires Java 1.1 and up

Exception :

IllegalArgumentException

– the┬áIllegalArgumentException will be thrown by skip() method if the argument n is negative

IOException

–┬áIOException will be thrown if I/O error occurs

Discussion :

The BufferedReader skip() method takes an argument of long which signifies how many characters to be skip on the inputstream. This is used when we are caught in a scenario on which on reading characters on the input stream we want to omit character sequences.

Java Code Example :

This java example source code demonstrates the use of skip() method of BufferedReader class. Basically we read the user input from the console and then we skip 8 characters using the skip method. The readLine() method were used to print what is remaining on the input stream after 8 characters were skipped.

Sample Output :

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

Similar Method :

  • N/A

Suggested Reading List :

References :