自动释放资源
- 从JDK1.7开始,Closeable extends AutoCloseable
- 在try后的()中创建资源,无需finally,系统会自动释放资源。
- 多个资源用分号;隔开。
String iPath = "C:\inputPath\"; String oPath = "C:\outputPath\"; List参考资料names = getNames(iPath, oPath).stream() .filter(name -> { try(FileChannel ic= new FileInputStream(new File(iPath, name)).getChannel(); FileChannel oc= new FileOutputStream(new File(oPath, name)).getChannel() ){ oc.transferFrom(ic, 0, ic.size()); } catch ( Exception e){ return false; } return true; }).collect(Collectors.toList());
AutoCloseable (Java Platform SE 8 )



