Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update</h2> <p>To get an array of files inside a zip, they must first be extracted into a temporary location:</p> <pre><code>import java.util.zip.*; import java.io.File; import java.util.ArrayList; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Enumeration; import java.io.IOException; public class ZipFileExtractor { public static void main(String[] args) { File[] zipFiles = ZipFileExtractor.getFileArray("archive.zip"); System.out.println(zipFiles.length); } public static File[] getFileArray(String archiveFileName) { ArrayList&lt;File&gt; zipArrayList = new ArrayList&lt;File&gt;(); try { ZipFile zFile = new ZipFile(archiveFileName); for (Enumeration&lt;? extends ZipEntry&gt; e = zFile.entries(); e.hasMoreElements(); ) { ZipEntry zEntry = e.nextElement(); InputStream in = zFile.getInputStream(zEntry); File temp = File.createTempFile(zFile.getName(), null); temp.deleteOnExit(); FileOutputStream out = new FileOutputStream(temp); byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); } zipArrayList.add(temp); } } catch (IOException e) { } return zipArrayList.toArray(new File[zipArrayList.size()]); } } </code></pre> <p>&nbsp;</p> <hr> <p>&nbsp;</p> <p>There is an API class called <a href="http://docs.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html" rel="nofollow">ZipInputStream</a> in <code>java.util.zip</code> package.</p> <p>It has a bunch of methods, among them <code>getNextEntry()</code> that pretty much does it:</p> <pre><code>ArrayList&lt;ZipEntry&gt; zipArrayList = new ArrayList&lt;ZipEntry&gt;(); ZipInputStream zis = ZipInputStream(new FileInputStream("archive.zip")); while ((ZipEntry ze = zis.getNextEntry()) != null) { zipArrayList.add(ze.getName()); } </code></pre> <p>I haven't tried compiling the above code, so it might have a few issues but I hope the idea is clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload