java - How to check existence of a JAR file and a specific file inside JAR? -
assume file name in url:
url file = new url("jar:file:/path/to/foo.jar!/meta-inf/file.txt");
this operation leads ioexception
if there no foo.jar
or there no file.txt
inside existing jar:
import org.apache.commons.io.fileutils; fileutils.copyurltofile(file, /* other file */);
is possible validate file existence without exception catching?
you can use java.util.jar.jarfile class, , use getjarentry method see if file exists.
jarfile jar = new jarfile("foo.jar"); jarentry entry = jar.getjarentry("meta-inf/file.txt"); if (entry != null) { // meta-inf/file.txt exists in foo.jar }
Comments
Post a Comment