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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -