From e19ed8845d4cf9169af8490194305b6e2d5194fd Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:08:16 +0300 Subject: [PATCH] fix #1343 --- .../java/ru/vtosters/lite/utils/VKAccountDB.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/utils/VKAccountDB.java b/app/src/main/java/ru/vtosters/lite/utils/VKAccountDB.java index 3c3cad1b6..d353c0de3 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/VKAccountDB.java +++ b/app/src/main/java/ru/vtosters/lite/utils/VKAccountDB.java @@ -70,19 +70,22 @@ public static void saveData() { LifecycleUtils.getCurrentActivity().requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 228); } - var db = getDatabase().getReadableDatabase(); - var dateFormat = new SimpleDateFormat("yyyy-MM-dd.HH-mm-ss", Locale.getDefault()); - var dir = new File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS), "/VTLBackups/"); - var file = new File(dir, "saved_accounts_" + dateFormat.format(new Date()) + ".vtl"); + SQLiteDatabase db = getDatabase().getReadableDatabase(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd.HH-mm-ss", Locale.getDefault()); + File dir = new File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS), "/VTLBackups/"); + File file = new File(dir, "saved_accounts_" + dateFormat.format(new Date()) + ".vtl"); try (InputStream inputStream = new FileInputStream(db.getPath())) { - dir.mkdirs(); + if (!dir.exists()) { + dir.mkdirs(); + } FileOutputStream outputStream = new FileOutputStream(file); byte[] buff = new byte[1024]; int read; - while ((read = inputStream.read(buff, 0, buff.length)) > 0) + while ((read = inputStream.read(buff, 0, buff.length)) > 0) { outputStream.write(buff, 0, read); + } inputStream.close(); outputStream.close();