Java.util.Scanner.ioException() Method

Advertisements


Description

The java.util.Scanner.ioException() method returns the IOException last thrown by this Scanner's underlying Readable. This method returns null if no such exception exists.

Declaration

Following is the declaration for java.util.Scanner.ioException() method

public IOException ioException()

Parameters

  • NA

Return Value

This method returns the last exception thrown by this scanner's readable

Exception

  • NA

Example

The following example shows the usage of java.util.Scanner.ioException() method.

package com.tutorialspoint;

import java.util.*;

public class ScannerDemo {

   public static void main(String[] args) {

      String s = "Hello World! 3 + 3.0 = 6 ";

      // 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();
   }
}

Let us compile and run the above program, this will produce the following result:

Hello World! 3 + 3.0 = 6 
null



Advertisements
Advertisements