diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index b3ee9f9db..dd634489a 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -507,15 +507,14 @@ public class Utils { public static File copyToTempFile(Context context, InputStream input, String name) throws IOException { File file = createTempFile(context, name); - FileOutputStream out = new FileOutputStream(file); - byte[] buf = new byte[4096]; - int len; - while ((len = input.read(buf)) != -1) { - out.write(buf, 0, len); + try (input; FileOutputStream out = new FileOutputStream(file)) { + byte[] buf = new byte[4096]; + int len; + while ((len = input.read(buf)) != -1) { + out.write(buf, 0, len); + } + return file; } - out.close(); - input.close(); - return file; } public static String saveTempImage(Context context, Bitmap in, String name, Bitmap.CompressFormat format) {