From 770b28f2418e9e875252f7a30213803faa1a9e08 Mon Sep 17 00:00:00 2001 From: Holger Ludvigsen Date: Mon, 5 Nov 2018 15:39:11 +0100 Subject: [PATCH] FileOutputStream is never closed The output file stream is not closed, so it is still in use by the Java process after the code runs. I noticed this when trying to delete the output files right afterwards. --- .../src/main/java/com/baeldung/download/FileDownload.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-io/src/main/java/com/baeldung/download/FileDownload.java b/core-java-io/src/main/java/com/baeldung/download/FileDownload.java index c7dd154023..a099406d4c 100644 --- a/core-java-io/src/main/java/com/baeldung/download/FileDownload.java +++ b/core-java-io/src/main/java/com/baeldung/download/FileDownload.java @@ -45,6 +45,7 @@ public class FileDownload { FileOutputStream fileOutputStream = new FileOutputStream(localFilename); FileChannel fileChannel = fileOutputStream.getChannel()) { fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE); + fileOutputStream.close(); } }