Scanner ioException() method in Java with Examples
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 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(); } } |
gfg geeks! null
Program 2:
// 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(); } } |
gopal dave! null
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#ioException()
Recommended Posts:
- Formatter ioException() method in Java with Examples
- Scanner useRadix() method in Java with Examples
- Scanner reset() method in Java with Examples
- Scanner radix() method in Java with Examples
- Scanner nextBigInteger() method in Java with Examples
- Scanner nextByte() method in Java with Examples
- Scanner useDelimiter() method in Java with Examples
- Scanner close() method in Java with Examples
- Scanner delimiter() method in Java with Examples
- Scanner findInLine() method in Java with Examples
- Scanner useLocale() method in Java with Examples
- Scanner nextShort() method in Java with Examples
- Scanner toString() method in Java with Examples
- Scanner nextFloat() method in Java with Examples
- Scanner nextInt() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



