pull/66/head
kunfei 5 years ago
parent b6691472bf
commit 45d74ba7c1
  1. 17
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt

@ -5,6 +5,23 @@ import android.net.Uri
object DocumentUtils { 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? { fun readText(context: Context, uri: Uri): String? {
readBytes(context, uri)?.let { readBytes(context, uri)?.let {
return String(it) return String(it)

Loading…
Cancel
Save