Created
March 6, 2021 07:42
-
-
Save abircse/cf5a329ffcb4f0d28dbc10b2ccd59d71 to your computer and use it in GitHub Desktop.
ReadHtmlFileInText
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
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