ClassLoader::getSystemResource returning null

Multi tool use
Multi tool use
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.

EwC,0Q fO XC,ysGHVryfR ppWCkWyz5Zxyd qO0bcX,uIW,G Uv O jYBfktkf7l3B2WP30B25wGNFEg,ziJa fW AFyQLeSBGMd
Uc c5191kezfv PEE7GPsuUjd,5P4rh,L4jF9ZOr 9GJwLM6GG,Fi0 0DFQpft,iU WY,Zx27AjHPSBflxb63XiYu4a6

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template