java.util.Scanner類的ioException()方法返回此Scanner的基礎Readable引發的最後一次IOException。如果不存在此類異常,則此方法返回null。
用法:
public IOException ioException()
返回值:此函數返回此掃描儀的可讀性引發的最後一個異常。
以下示例程序旨在說明上述函數:
示例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
示例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
參考: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#ioException()
相關用法
- Java Formatter ioException()用法及代碼示例
- Java Scanner nextInt()用法及代碼示例
- Java Scanner useRadix()用法及代碼示例
- Java Scanner nextBigInteger()用法及代碼示例
- Java Scanner nextLine()用法及代碼示例
- Java Scanner nextByte()用法及代碼示例
- Java Scanner nextLong()用法及代碼示例
- Java Scanner delimiter()用法及代碼示例
- Java Scanner close()用法及代碼示例
- Java Scanner nextFloat()用法及代碼示例
- Java Scanner findInLine()用法及代碼示例
- Java Scanner reset()用法及代碼示例
- Java Scanner radix()用法及代碼示例
- Java Scanner nextShort()用法及代碼示例
- Java Scanner nextDouble()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Scanner ioException() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。