Created
February 17, 2021 06:03
-
-
Save abircse/87382574c29e827fcbf7e2227ea3beea to your computer and use it in GitHub Desktop.
Converthtmlfiletotext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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