如何从 JAR 存档中读取文件? [英] How to read a file from JAR archive?
本文介绍了如何从 JAR 存档中读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 test.jar
文件中读取 /test/a.xml
的内容(它们都是变量,当然,不是常量).最简单的方法是什么?
I need to read the content of /test/a.xml
from a test.jar
file (they are both variables, of course, not constants). What is the simplest way to do it?
File file = new File("test.jar");
String path = "/test/a.xml";
String content = // ... how?
推荐答案
这个怎么样:
JarFile file = new JarFile(new File("test.jar"));
JarEntry entry = file.getJarEntry("/test/a.xml");
String content = IOUtils.toString(file.getInputStream(entry));
这篇关于如何从 JAR 存档中读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文