0

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.

Ahmad Beg
  • 4,285
  • 3
  • 14
  • 5

1 Answers1

0

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.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275