Java流的正确关闭方式

时间:2014-07-11 10:09:42   收藏:0   阅读:551

因为流是无论如何一定要关闭的,所以要写在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;
                }
            }
        }

Java流的正确关闭方式,布布扣,bubuko.com

原文:http://www.cnblogs.com/hamhog/p/3834423.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!