Resources in a .jar file are not files in the sense that the OS can access them directly through the regular file access APIs.
And since it java.io.Fileis just such a file (i.e. a thing that looks like a file in the OS), it cannot be used to refer to anything in the .jar file.
A possible workaround is to extract the resource into a temporary file and link to it with File.
Note that usually APIs that attempt to process files should be written to handle InputStream/ OutputStreamin order to allow such operations.
source
share