使用布尔变量来跟踪是否发生异常
import java.io.FileInputStream;//来自 n o w j a v a . c o m - 时代Java import java.io.FileNotFoundException; public class Main { public static boolean openFile(String name) { boolean fileOpened = false; try { FileInputStream f = new FileInputStream(name); fileOpened = true; } catch (FileNotFoundException e) { } return fileOpened; } /**来自 时代Java公众号 - nowjava.com**/ }