Read a file from inside of an external Jar file?

后端 未结 2 1734
天涯浪人
天涯浪人 2021-01-07 00:16

I\'m trying to read a file from inside an external jar using java.. For example, I have two jar files. One is \"foo.jar\" the other is \"bar.jar\". Inside of \"bar.jar\" is

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 00:28

    If the jar is in your classpath then getResourceAsStream will work, but note that it will find the first instance in your classpath. If foo.jar and bar.jar both contain this file then it will return whichever jar is first in classpath.

    To read it from the jar use JarFile.getEntry and JarFile.getInputStream

提交回复
热议问题