// Q: How do I get input from a text file contained inside a zip file?

import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.util.ArrayList;
import java.util.Scanner;

public class ZipFiles
{
	public static void main( String[] args ) throws Exception
	{
		String filename = "test.zip";
		ZipFile zfile = new ZipFile(filename);

		// build an ArrayList of the ZipEntries in the ZipFile
		ArrayList<ZipEntry> toc = new ArrayList<ZipEntry>();
		java.util.Enumeration e = zfile.entries();
		while ( e.hasMoreElements() )
			toc.add((ZipEntry)e.nextElement());

		// Display a table of contents for the ZipFile
		System.out.println("The ZipFile \"" + filename + "\" contains " + zfile.size() + " entries:");
		for ( ZipEntry z : toc )
			System.out.println( "\t" + z.getName() );

		// Display contents of first compressed file
		Scanner filein = new Scanner( zfile.getInputStream( toc.get(0) ) );

		System.out.println("\nContents of \"" + toc.get(0).getName() + "\":");
		while ( filein.hasNext() )
			System.out.println( filein.nextLine() );
		filein.close();

	}
}
