From 2934bb11ea9d4e9580ecbf012e38c9579e415ee7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 15 May 2018 19:41:40 +0100 Subject: [PATCH] Close file ready with try-with-resources --- .../kemitix/checkstyle/ruleset/builder/ReadmeWriter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java index 12d1c41..3cc8ae5 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java @@ -32,6 +32,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Writes the README file. @@ -94,8 +95,9 @@ class ReadmeWriter implements CommandLineRunner { } private String readFile(final Path file) throws IOException { - return Files.lines(file, StandardCharsets.UTF_8) - .collect(Collectors.joining(NEWLINE)); + try (Stream lines = Files.lines(file, StandardCharsets.UTF_8)) { + return lines.collect(Collectors.joining(NEWLINE)); + } } }