Skip to content

Instantly share code, notes, and snippets.

@abircse
Created March 6, 2021 07:42
Show Gist options
  • Save abircse/cf5a329ffcb4f0d28dbc10b2ccd59d71 to your computer and use it in GitHub Desktop.
Save abircse/cf5a329ffcb4f0d28dbc10b2ccd59d71 to your computer and use it in GitHub Desktop.
ReadHtmlFileInText
fun readHtmlFile(section: String, fileName: String, context: Context): String? {
val returnString = StringBuilder()
var fIn: InputStream? = null
var isr: InputStreamReader? = null
var input: BufferedReader? = null
try {
fIn = context.resources.assets
.open(section + fileName)
isr = InputStreamReader(fIn)
input = BufferedReader(isr)
var line: String? = ""
while (input.readLine().also { line = it } != null) {
returnString.append(line)
}
} catch (e: Exception) {
e.message
} finally {
try {
isr?.close()
fIn?.close()
input?.close()
} catch (e2: Exception) {
e2.message
}
}
return HtmlCompat.fromHtml(returnString.toString(), HtmlCompat.FROM_HTML_MODE_LEGACY).toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment