Skip to content
Advertisement

java.nio.file.Path for a classpath resource

Is there an API to get a classpath resource (e.g. what I’d get from Class.getResource(String)) as a java.nio.file.Path? Ideally, I’d like to use the fancy new Path APIs with classpath resources.

Advertisement

Answer

This one works for me:

return Path.of(ClassLoader.getSystemResource(resourceName).toURI());
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement