Java – how do I read files from a jar archive?

See the English answer > How do I read a resource file from a Java jar file? 8

File file = new File("test.jar");
String path = "/test/a.xml";
String content = // ... how?

Solution

How's this?

JarFile file = new JarFile(new File("test.jar"));
JarEntry entry = file.getJarEntry("/test/a.xml");
String content = IoUtils.toString(file.getInputStream(entry));
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
分享
二维码
< <上一篇
下一篇>>