Reputation: 563
I get jar files from net. I've been able to open it and to search for a file(.txt file) that I need inside it. For doing that I am using JarEntry and method getNextJarEntry(). Finally when I identify the file I need I would like to save it in some directory on my disc. I don't know how to do this. The object I have after file identification is JarEntry which corresponds to the file I want to save. Can anybody suggest me a way how to store the file I need?
My bad, I only have JarInputStream and not the jar itself.
Upvotes: 0
Views: 538
Reputation: 5291
You might load the JAR using a custom classloader (java.net.URLClassloader
), then get the resource using getResourceAsStream
.
Upvotes: 1
Reputation: 691685
Use the JarFile.getInputStream(ZipEntry)
method, read all the bytes from the input stream, and write them to a FileOutputStream.
Upvotes: 2
Reputation: 47608
On the original JarFile
object, you can pass the JarEntry
and get an InputStream
:
InputStream getInputStream(ZipEntry ze)
Upvotes: 2