java.nio.file.Path for a classpath resource

Louis Wasserman picture Louis Wasserman · Mar 30, 2013 · Viewed 117.4k times · Source

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.

Answer

keyoxy picture keyoxy · May 14, 2014

This one works for me:

return Paths.get(ClassLoader.getSystemResource(resourceName).toURI());