需要使用 try-with-resources 语句来保证stream的close方法被调用,从而关闭打开的文件
// try-with-resources语句,等同于try-catch-finally try(Streamstream = Files.lines(Paths.get(filePath))){ stream.collect(Collectors.toList()); } catch (IOException e){ logger.error("get content from{} error,{}",filePath, e); }



