You're on the right track with ZipFile
, and I don't think you need to extract to disk before viewing the images.
A ZipFile
object will give you a list of its contents with entries()
. You can iterate this collection of ZipEntry
objects to present a choice of which file to view, and of course filter it to known extensions if you desire.
Strangely enough it's the ZipFile
object and not the the individual ZipEntry
objects that will give you an InputStream
for the given entry. You can read this object into a byte[]
in memory and send it to the component that will be responsible for displaying the image.
One caveat is that with zip files, in order to get to the last file stored in the zip it will basically have to decompress the whole archive which can be time consuming. So it may make sense to cache files on disk or an in-memory LRU cache depending on the usage pattern.
You didn't mention if this is for a Swing application, but if it is this might be helpful for displaying the images:
http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html