Java Scanner - IOException() Method
The java.util.Scanner.IOException() method returns the IOException last thrown by the Scanner's underlying Readable. The method returns null if no such exception exists.
Syntax
public IOException ioException()
Parameters
No parameter is required.
Return Value
Returns the last exception thrown by this scanner's readable.
Exception
NA.
Example:
In the example below, the java.util.Scanner.IOException() method is used to check if there is any IOException thrown by the Scanner's underlying Readable.
import java.util.*; public class MyClass { public static void main(String[] args) { //String to scan String MyString = "Hello World 10 + 20 = 30.0"; //creating a Scanner Scanner MyScan = new Scanner(MyString); //print the nextLine token System.out.println(MyScan.nextLine()); //check if there is any IOException System.out.println(MyScan.ioException()); //close the scanner MyScan.close(); } }
The output of the above code will be:
Hello World 10 + 20 = 30.0 null
❮ Java.util - Scanner