ClassLoader::getSystemResource returning null

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


ClassLoader::getSystemResource returning null



It used to work in the past, but I don't what happened in the middle, now it returns always null.


null



The file to read is in the project root diretory, which corresponds to the output of Paths.get(".").


Paths.get(".")



Note: function is top-level



I'm reading the imgui.ini file here


imgui.ini



fileLoadToLines(iniFilename)


fileLoadToLines(iniFilename)



where it's so defined



fun fileLoadToLines(filename: String) = ClassLoader.getSystemResourceAsStream(filename)?.use { it.bufferedReader().readLines() }


fun fileLoadToLines(filename: String) = ClassLoader.getSystemResourceAsStream(filename)?.use { it.bufferedReader().readLines() }



Tried also the other Thread.currentThread().contextClassLoader, no success


Thread.currentThread().contextClassLoader



What's the problem?




1 Answer
1



The project root directory is typically the default current working directory, but not necessarily on the classpath. That's why Paths.get(".") returns it, while the classloader doesn't find the file under it, because the latter goes by what's in the classpath.


Paths.get(".")



It used to work probably because you had the project root added to the runtime classpath. The solution I would recommend is instead of using a classloader, just use the file system API in java.io to load it.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to scale/resize CVPixelBufferRef in objective C, iOS

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

openssl aes gcm encryption with authentication TAG; command line