因为流是无论如何一定要关闭的,所以要写在finally里。如下:
BufferedReader reader = null; try { reader = (BufferedReader) getReaderFromFile(file); …… } catch (IOException e) { throw e; } finally { if (reader != null) { try { reader.close(); } catch (IOException e){ throw e; } } }
时间: 2024-10-25 12:44:54