Java流的正确关闭方式

因为流是无论如何一定要关闭的,所以要写在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;
                }
            }
        }
原文地址:https://www.cnblogs.com/hamhog/p/3834423.html