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.


    public IOException ioException();


  • 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.


// 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.nextLine(): Hi, [IncludeHelp] +
sc.ioException(): null


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.