I am working with an external API which provides the following function:
public void process(File file) {
}
In my case, the file to be provided is in a JAR in the classpath. Is there a way to provide a File
representing this file to process(File)
?
I tried the following:
new File(getClass().getClassLoader().getResource("my-file.txt").toURI()))
This gives the error: URI is not hierarchical
.
I did some researching and understood that files on the classpath should not be considered as a regular file, but as a resource. This makes me believe that there is no easy way to construct a File
for that resource.
Should I copy the resource to a temporary file first?