diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java index 97a6b7f..4489f52 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java @@ -42,13 +42,14 @@ public void download() throws Exception { if (!file.exists()) { file.createNewFile(); } - FileOutputStream fos = new FileOutputStream(file); - byte[] b = new byte[1024]; - int length; - while ((length = is.read(b)) > 0) { - fos.write(b, 0, length); + try (FileOutputStream fos = new FileOutputStream(file)) { + byte[] b = new byte[1024]; + int length; + while ((length = is.read(b)) > 0) { + fos.write(b, 0, length); + } + is.close(); + fos.close(); } - is.close(); - fos.close(); } }