Skip to content

Instantly share code, notes, and snippets.

@abircse
Created February 17, 2021 06:03
Show Gist options
  • Save abircse/87382574c29e827fcbf7e2227ea3beea to your computer and use it in GitHub Desktop.
Save abircse/87382574c29e827fcbf7e2227ea3beea to your computer and use it in GitHub Desktop.
Converthtmlfiletotext
val textView = findViewById<TextView>(R.id.textview)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.text = Html.fromHtml(readTxt(), Html.FROM_HTML_MODE_LEGACY)
} else {
textView.text = HtmlCompat.fromHtml(readTxt()!!, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
}
private fun readTxt(): String? {
val inputStream: InputStream = assets.open("1a_1_001.html")
val byteArrayOutputStream = ByteArrayOutputStream()
var i: Int
try {
i = inputStream.read()
while (i != -1) {
byteArrayOutputStream.write(i)
i = inputStream.read()
}
inputStream.close()
} catch (e: IOException) {
// TODO Auto-generated catch block
e.printStackTrace()
}
return byteArrayOutputStream.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment