Skip to content

Commit 770b28f

Browse files
authored
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.
1 parent d83eb69 commit 770b28f

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎core-java-io/src/main/java/com/baeldung/download/FileDownload.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static void downloadWithJavaNIO(String fileURL, String localFilename) thr
4545
FileOutputStream fileOutputStream = new FileOutputStream(localFilename); FileChannel fileChannel = fileOutputStream.getChannel()) {
4646

4747
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
48+
fileOutputStream.close();
4849
}
4950
}
5051

0 commit comments

Comments
 (0)