问题与练习

Questions

try {
    
} finally {
    
}
catch (Exception e) {
     
}

使用这种类型的异常处理程序有什么问题?

try {

} catch (Exception e) {
    
} catch (ArithmeticException a) {
    
}

Exercises

public static void cat(File file) {
    RandomAccessFile input = null;
    String line = null;

    try {
        input = new RandomAccessFile(file, "r");
        while ((line = input.readLine()) != null) {
            System.out.println(line);
        }
        return;
    } finally {
        if (input != null) {
            input.close();
        }
    }
}

检查一下你的答案。

首页