Skip to content

Instantly share code, notes, and snippets.

@tugceaktepe
Created June 15, 2023 20:06
Show Gist options
  • Save tugceaktepe/95390c374a57b1920b3c0fbd38408bb5 to your computer and use it in GitHub Desktop.
Save tugceaktepe/95390c374a57b1920b3c0fbd38408bb5 to your computer and use it in GitHub Desktop.
FileReader for json parse
object FileReader {
fun readStringFromFile(fileName: String): String {
try {
val inputStream = (InstrumentationRegistry.getInstrumentation().targetContext
.applicationContext as HiltTestApplication).assets.open(fileName)
val builder = StringBuilder()
val reader = InputStreamReader(inputStream, "UTF-8")
reader.readLines().forEach {
builder.append(it)
}
return builder.toString()
} catch (e: IOException) {
throw e
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment