Issue
hello i'm trying to read json file located at resources folder in androidTest. I'm able to access json file located at resources folder in Test/resources but not in androidTest/resources.
I use following to get the json file in the Test/resources folder.
private fun getJson(path: String): String {
val uri = this.javaClass.classLoader?.getResource(path)
val file = File(uri?.path ?: "")
return String(file.readBytes())
}
Is there a way i can access the file under androidTest/resources ?
Solution
private fun getJson(fileName: Int): String {
val inputStream = InstrumentationRegistry.getInstrumentation().targetContext.resources.openRawResource(fileName)
val s = Scanner(inputStream).useDelimiter("\\A")
return if (s.hasNext()) s.next() else ""
}
Answered By - Abhi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.