javajava-7nio2

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.


Solution

  • This one works for me:

    return Path.of(ClassLoader.getSystemResource(resourceName).toURI());