Last active
October 10, 2017 04:39
-
-
Save sgdan/9822c3c6253c132121b752e9c6bf056b to your computer and use it in GitHub Desktop.
Compare loading a text resource via classpath or file
This file contains 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
// Assume folder containing script is in the classpath | |
// To append current folder to classpath can pass: -Xbootclasspath/a:. | |
// load from file system | |
val fileContent = java.io.File("loadResource.kts").readText() | |
println("file content length: ${fileContent.length}") | |
// load via class path (can also use javaClass.getResource method but seems more reliable to go via class loader) | |
val urlContent = javaClass.classLoader.getResource("loadResource.kts").readText() | |
println("url content length: ${urlContent.length}") | |
assert(fileContent == urlContent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment