Skip to content

Instantly share code, notes, and snippets.

@sgdan
Last active October 10, 2017 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgdan/9822c3c6253c132121b752e9c6bf056b to your computer and use it in GitHub Desktop.
Save sgdan/9822c3c6253c132121b752e9c6bf056b to your computer and use it in GitHub Desktop.
Compare loading a text resource via classpath or file
// 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