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 {