From f370e83a3d79a947d8de1913d24cf34f80fa56cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/entities/Book.kt | 2 +- .../main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 0d853d2cf..27f9baec8 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -82,7 +82,7 @@ data class Book( variable = GSON.toJson(variableMap) } - fun getCharset(): Charset { + fun fileCharset(): Charset { return charset(charset ?: "UTF-8") } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 2a21a0e5f..145558a07 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -30,7 +30,7 @@ object AnalyzeTxtFile { fun analyze(context: Context, book: Book): ArrayList { val bookFile = getBookFile(context, book) book.charset = EncodingDetect.getEncode(bookFile) - val charset = book.getCharset() + val charset = book.fileCharset() val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") @@ -190,7 +190,7 @@ object AnalyzeTxtFile { val extent = (bookChapter.end!! - bookChapter.start!!).toInt() val content = ByteArray(extent) bookStream.read(content, 0, extent) - return String(content, book.getCharset()) + return String(content, book.fileCharset()) } private fun getBookFile(context: Context, book: Book): File {