Close file ready with try-with-resources

This commit is contained in:
Paul Campbell 2018-05-15 19:41:40 +01:00
parent 714aeca9b4
commit 2934bb11ea

View file

@ -32,6 +32,7 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* Writes the README file. * Writes the README file.
@ -94,8 +95,9 @@ class ReadmeWriter implements CommandLineRunner {
} }
private String readFile(final Path file) throws IOException { private String readFile(final Path file) throws IOException {
return Files.lines(file, StandardCharsets.UTF_8) try (Stream<String> lines = Files.lines(file, StandardCharsets.UTF_8)) {
.collect(Collectors.joining(NEWLINE)); return lines.collect(Collectors.joining(NEWLINE));
}
} }
} }