Created
January 31, 2018 12:57
-
-
Save bastman/a337b201b7275f49f4adc9b4cde70668 to your computer and use it in GitHub Desktop.
Kotlin function to load content of a packaged resource
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 loadResource(resource: String): String = | |
try { | |
object {}.javaClass.getResource(resource) | |
.readText(Charsets.UTF_8) | |
} catch (all: Exception) { | |
throw RuntimeException("Failed to load resource=$resource!", all) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmm why doesn't
object {}.javaClass
exist for me? I'm trying to do this from inside a multiplatform lib...