public void automaticallyCloseResource() {
File file = new File("./tmp.txt");
try (FileInputStream inputStream = new FileInputStream(file);)
{ // use the inputStream to read a file }
catch (FileNotFoundException e)
{ log.error(e); }
catch (IOException e)
{ log.error(e); }
}
著作权归@pdai所有 原文链接:https://pdai.tech/md/interview/x-interview.html
- try-with-resource resource Java with trytry-with-resources resources java with try-with-resource resource java with try-with-resource语法resource java try-with-resource try-with-resources try-with-resources妙招resources代码 try-with-resource resource方式 资源 try-with-resources语句resources with try-with-resources resources方式 资源 try-with-resource语法resource with