Skip to content

Instantly share code, notes, and snippets.

@bastman
Created January 31, 2018 12:57
Show Gist options
  • Save bastman/a337b201b7275f49f4adc9b4cde70668 to your computer and use it in GitHub Desktop.
Save bastman/a337b201b7275f49f4adc9b4cde70668 to your computer and use it in GitHub Desktop.
Kotlin function to load content of a packaged resource
fun loadResource(resource: String): String =
try {
object {}.javaClass.getResource(resource)
.readText(Charsets.UTF_8)
} catch (all: Exception) {
throw RuntimeException("Failed to load resource=$resource!", all)
}
@ddnn55
Copy link

ddnn55 commented May 7, 2019

hmm why doesn't object {}.javaClass exist for me? I'm trying to do this from inside a multiplatform lib...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment