该接口用于try-with-resources语法糖提供支持,用于自动关闭资源做用code
close
方法最后调用的基本上都是本地方法。例子:接口
public class AutoCloseableTest { @Test public void test(){ try(FileInputStream inputStream=new FileInputStream(new File("test.txt"))){ //do somethings } catch (IOException e) { e.printStackTrace(); } //不须要在使用finally去关闭资源了,方便快捷 } }