Scanner ioException() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The ioException() method of java.util.Scanner class returns the IOException last thrown by this Scanner's underlying Readable. This method returns null if no such exception exists. Syntax: public IOException ioException() Return Value: This function returns the last exception thrown by this scanner's readable. Below programs illustrate the above function: Program 1: Java // Java program to illustrate the // ioException() method of Scanner class in Java // without parameter import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "gfg geeks!"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print the line System.out.println("" + scanner.nextLine()); // check if there is an IO exception System.out.println("" + scanner.ioException()); // close the scanner scanner.close(); } } Output: gfg geeks! null Program 2: Java // Java program to illustrate the // ioException() method of Scanner class in Java // without parameter import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "gopal dave!"; // new scanner with the specified String Object Scanner scanner = new Scanner(s); // print the line System.out.println("" + scanner.nextLine()); // checks if there is an IO exception System.out.println("" + scanner.ioException()); // close the scanner scanner.close(); } } Output: gopal dave! null Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#ioException() Comment More infoAdvertise with us Next Article Scanner hasNextInt() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-Scanner Practice Tags : Java Similar Reads Scanner hasNextInt() method in Java with Examples The hasNextInt() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Int value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix an 3 min read Scanner hasNextInt() method in Java with Examples The hasNextInt() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Int value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix an 3 min read Scanner hasNextLine() method in Java with Examples The hasNextLine() method of java.util.Scanner class returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advance past any input. Syntax: public boolean hasNextLine() Parameters: The function does not accepts any param 2 min read Scanner hasNextLine() method in Java with Examples The hasNextLine() method of java.util.Scanner class returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advance past any input. Syntax: public boolean hasNextLine() Parameters: The function does not accepts any param 2 min read Scanner hasNextLong() method in Java with Examples The hasNextLong() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Long value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix 3 min read Scanner hasNextLong() method in Java with Examples The hasNextLong() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Long value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix 3 min read Like