From 45d74ba7c1b9a32e580922e0fd33289f7fe76a14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 21:23:22 +0800 Subject: [PATCH] up --- .../java/io/legado/app/utils/DocumentUtils.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 276cfa473..e10170892 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -5,6 +5,23 @@ import android.net.Uri object DocumentUtils { + fun writeText(context: Context, data: String, fileUri: Uri): Boolean { + return writeBytes(context, data.toByteArray(), fileUri) + } + + fun writeBytes(context: Context, data: ByteArray, fileUri: Uri): Boolean { + try { + context.contentResolver.openOutputStream(fileUri)?.let { + it.write(data) + it.close() + return true + } + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + return false + } + fun readText(context: Context, uri: Uri): String? { readBytes(context, uri)?.let { return String(it)