用finally语句捕获两个异常
import java.io.*; public class Cat { /**来自 n o w j a v a . c o m - 时 代 Java**/ public static void concatenate(String fileName) { RandomAccessFile raf = null; String line = null; try { raf = new RandomAccessFile(fileName, "r"); while ((line = raf.readLine()) != null) { System.out.println(line); } return; } catch (FileNotFoundException fnf) { System.err.println("File: " + fileName + " not found."); } catch (Exception e) { System.err.println(e.toString()); } finally { if (raf != null) {// from nowjava.com - 时代Java try { raf.close(); } catch (IOException io) { } } } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) Cat.concatenate(args[i]); } }