[英]Why does this code throw an IOException?
為什么此代碼會引發IOException
?
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner scan1 = new Scanner(new File("File1.txt"));
Scanner scan2 = new Scanner(new File("File2.txt"))) {
} catch (IOException e) {
System.out.println("An IOException has been thrown.");
}
System.out.println("Done!");
}
}
我正在從一本書中學習,但是不明白為什么它會引發異常。 任何幫助表示贊賞!
因為構造函數Scanner(File)
拋出FileNotFoundException
,它是IOException
的子類。 檢查javadoc以獲取更多詳細信息 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.