Home »
Java programming language
Java Scanner ioException() Method with Example
Scanner Class ioException() method: Here, we are going to learn about the ioException() method of Scanner Class with its syntax and example.
Submitted by Preeti Jain, on February 18, 2020
Scanner Class ioException() method
- ioException() method is available in java.util package.
- ioException() method is used to get the IOException when it is thrown by Scanner Readable otherwise it returns null.
- ioException() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- ioException() method does not throw an exception at the time of returning IOException.
Syntax:
public IOException ioException();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is IOException, it returns IOException when it is thrown by this Scanner Readable otherwise it returns null.
Example:
// Java program to demonstrate the example
// of IOException ioException() method of Scanner
import java.util.*;
public class IOExceptionOfScanner {
public static void main(String[] args) {
String str = "Hi, [IncludeHelp] +\n 10.0 true ";
// Instantiates a Scanner object with
// the given string str
Scanner sc = new Scanner(str);
// Display str
System.out.println("sc.nextLine(): " + sc.nextLine());
// By using ioException() method is
// to return an IOException if possible
System.out.println("sc.ioException(): " + sc.ioException());
// By using close() method is to
// close the Scanner object
sc.close();
}
}
Output
sc.nextLine(): Hi, [IncludeHelp] +
sc.ioException(): null