Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
/test/a.xml
test.jar
File file = new File("test.jar"); String path = "/test/a.xml"; String content = // ... how?
How about this:
JarFile file = new JarFile(new File("test.jar")); JarEntry entry = file.getJarEntry("/test/a.xml"); String content = IOUtils.toString(file.getInputStream(entry));
Add a comment
Use a ZipInputStream and search for your requested file.
ZipInputStream
FileInputStream fis = new FileInputStream(args[0]); ZipInputStream zis = new ZipInputStream(fis); ZipEntry ze; while ((ze = zis.getNextEntry()) != null) if(ze.getName().equals("/test/a.xml") { //use zis to read the file's content }
fis
InputStream
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
test.jar?