문제

I wanted to know the Apache library method IOUtils.closeQuitely does well with FileChannel. I see it takes Closeable as argument and FileChannel does implement it up in hierarachy. But can we face any issue down the line. Any experience one can share please.

도움이 되었습니까?

해결책

I think it's OK if we use it as IOUtils.closeQuietly API suggests, ie double-close

    FileChannel ch = null;
    try {
        ch = new FileInputStream("foo.txt").getChannel();
        // process
        ch.close();
    } catch (Exception e) {
        // error handling
    } finally {
        IOUtils.closeQuietly(ch);
    }

But try-with-resources if Java 7 is available is a much cleaner way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top