Java – how does my jar open itself as a stream?
•
Java
I'm trying to open a jar as a stream, but I can't understand where to get this stream
JarInputStream s = new JarInputStream(/* what is here? */);
Where do you get this stream? I'm trying to open the jar that I'm currently in charge of
Solution
From my answer to similar questions:
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
if (src != null) {
URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
/* Now examine the ZIP file entries to find those you care about. */
...
}
else {
/* Fail... */
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
