pull/84/head
kunfei 5 years ago
parent 9070f610ec
commit f370e83a3d
  1. 2
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 4
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt

@ -82,7 +82,7 @@ data class Book(
variable = GSON.toJson(variableMap)
}
fun getCharset(): Charset {
fun fileCharset(): Charset {
return charset(charset ?: "UTF-8")
}

@ -30,7 +30,7 @@ object AnalyzeTxtFile {
fun analyze(context: Context, book: Book): ArrayList<BookChapter> {
val bookFile = getBookFile(context, book)
book.charset = EncodingDetect.getEncode(bookFile)
val charset = book.getCharset()
val charset = book.fileCharset()
val toc = arrayListOf<BookChapter>()
//获取文件流
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 {

Loading…
Cancel
Save