Reputation: 3987
I need to read the file, that is inside the jar folder in this way:
DataSource coverdata = new FileDataSource(new File("here is the path"));
How do I get the exact path? I am using a library, so the only way I can acces file is new File()
, no inputstreams.
Upvotes: 1
Views: 1355
Reputation: 3380
What about creating a new temporal file, with the InputStream (getResourceAsStream() ) methods that @home already talked about, and then reading it as a normal file?
Upvotes: 0
Reputation: 115328
You are on the wrong way. File is only something that is directly written on file system. File inside jar is not a file from java API point of view.
To read this file you have to parse JAR using either JarInputStream or ZipInputStream, get to the interesting entry and read from the input stream. It is not hard to do but you have to write several lines of code.
Other approach is using VFS package from jakarta.org. It provides you unified view on elements of different files systems, ZIP, TAR and other container formats.
Upvotes: 1
Reputation: 12538
Call ClassLoader.getResourceAsStream()::InputStream
or ClassLoader.getResource()::URL
.
See:
The JAR file containing the requested file must be in the classpath.
Upvotes: 3