RAVITEJA SATYAVADA RAVITEJA SATYAVADA - 1 month ago 6
Java Question

Using zip file without extracting in java

I'm facing a problem that, we have a

.zip
file that contains some text files. Now I'm using java to access that files. If it is not in the
.zip
file I can read and print on my console easily using
FileInputStream
.

But how to read a file from
.zip
file? I use
J2SE
only..

Answer

You should try a ZipInputStream. The interface is a little obtuse, but you can use getNextEntry() to iterate through the items in the .zip file.

As a side note, the Java class-loader does exactly this to load classes from .jar files without extracting them first.

Comments