jdk7可以用 thy-with-resoucese, 不用手动关闭
查询资料都说要实现autoclouseable接口才能自动关闭流 ,但自测了多次,不管是否测试aoutocloeseable中的close()方法都可以自动关闭
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
try( BufferedWriter write= new BufferedWriter(new FileWriter("E:\\testAutoCloseable.txt"))){ write.write("自动关闭"); System.out.println(1111); } catch (IOException e) { e.printStackTrace(); }