Java – “convert to trial resources” in NetBeans – cool beans?

Netbeans 7.1. 2 has the following codes:

bufferedoutputstream bos = new bufferedoutputstream(new FileOutputStream(filename));
bos.write(newRawData);
bos.close();

A warning indicates that I "try to use resources instead" When I choose to do this, my code becomes:

try (bufferedoutputstream bufferedFos = new bufferedoutputstream(new FileOutputStream(filename))) {
        bufferedFos.write(newRawData);
    }

Does this look similar to the syntax of using (...) in C #? Do they work the same way? What are the disadvantages of using the second format? I'm afraid there's no BOS Close (), but doesn't this format be needed at all?

Solution

This is a new syntax introduced in Java 7. It is responsible for closing any resources you specify when declaring a try (...) statement More information can be found here So no, you don't have to be a BOS Close(), which is executed by Java You can sit down and relax The only drawback is that your code is only applicable to Java 7

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>