Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android API level < 19 and "try can use automatic resource management" warning

I have this piece of code

private void copyFile(File src, File dst) throws IOException {

    FileChannel inChannel = new FileInputStream(src).getChannel();
    FileChannel outChannel = new FileOutputStream(dst).getChannel();

    try {

        inChannel.transferTo(0, inChannel.size(), outChannel);

    }finally {

        if(inChannel != null) {

            inChannel.close();

        }

        outChannel.close();

    }

}

that generates the annoying warning "try can use automatic resource management". The prolem is I cannot use Java 7 try-with-resources cause my app targets api level 14 (got an error if I use it). Is there a way to suppress that annoying warning?

like image 945
Stack Diego Avatar asked Apr 07 '15 22:04

Stack Diego


1 Answers

@SuppressWarnings("TryFinallyCanBeTryWithResources") did the trick :)

like image 176
Stack Diego Avatar answered Nov 17 '22 20:11

Stack Diego