我的JAR如何将自己打开为流?

yeg*_*256 3 java

我正在尝试打开JAR作为流,但无法理解从哪里获取此流...

JarInputStream s = new JarInputStream(/* what is here? */);
Run Code Online (Sandbox Code Playgroud)

从哪里获得这个流?我正在尝试打开目前正在负责的JAR.

eri*_*son 5

对类似问题的回答:

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... */
}
Run Code Online (Sandbox Code Playgroud)