From d552c5d38a495280c4a0979e8e3d6f63e2c136ef Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 14:20:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/RealPathUtil.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt index 5ded2f823..3eedc2fde 100644 --- a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt +++ b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt @@ -102,8 +102,6 @@ object RealPathUtil { val projection = arrayOf( column ) - var input: FileInputStream? = null - var output: FileOutputStream? = null try { cursor = context.contentResolver.query(uri!!, projection, selection, selectionArgs, null) @@ -115,6 +113,8 @@ object RealPathUtil { e.printStackTrace() val file = File(context.cacheDir, "tmp") val filePath = file.absolutePath + var input: FileInputStream? = null + var output: FileOutputStream? = null try { val pfd = context.contentResolver.openFileDescriptor(filePathUri!!, "r") @@ -127,11 +127,12 @@ object RealPathUtil { while (input.read(bytes).also { read = it } != -1) { output.write(bytes, 0, read) } - input.close() - output.close() return File(filePath).absolutePath } catch (ignored: IOException) { ignored.printStackTrace() + } finally { + input?.close() + output?.close() } } finally { cursor?.close()