“Convert to try-with-resources” in Netbeans - Cool Beans?

后端 未结 2 711
轻奢々
轻奢々 2021-01-04 14:32

I have the following code in Netbeans 7.1.2:

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filename));
bos.write(newRawData);
bos.         


        
2条回答
  •  太阳男子
    2021-01-04 14:52

    This was a new syntax that was introduced in Java 7, which takes care of closing any resources you specify when declaring the try(...) statement. More info can be found here.
    So no, you don't have to do a bos.close(), it is performed by Java. You can just sit back and relax.
    The only downside is that your code works with Java 7+ only.

提交回复
热议问题