package com.gns.zip;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* Title:ZIPReader
* Description:
* Copyright: Copyright (c) 2013-2-27
* Company: ETHERGNS-COM
* @author guzi
* @version 1.0.0
*/
public class ZIPReader
{
public static void main ( String [] args )
throws IOException
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(new File("aa.zip")));
StringBuffer sb = new StringBuffer();
boolean flag = true;
while ( flag )
{
ZipEntry entry = zip.getNextEntry();
if ( entry != null )
{
sb.append(entry.getName() + "\t");
byte [] temp = new byte [120];
int leng = 0;
while ( leng != -1 )
{
leng = zip.read(temp);
if ( leng == -1 )
{
break;
}
sb.append(new String(temp, 0, leng));
}
sb.append("\r\n");
}
else
{
flag = false;
}
zip.closeEntry();
}
zip.close();
System.out.println(sb.toString());
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* Title:ZIPReader
* Description:
* Copyright: Copyright (c) 2013-2-27
* Company: ETHERGNS-COM
* @author guzi
* @version 1.0.0
*/
public class ZIPReader
{
public static void main ( String [] args )
throws IOException
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(new File("aa.zip")));
StringBuffer sb = new StringBuffer();
boolean flag = true;
while ( flag )
{
ZipEntry entry = zip.getNextEntry();
if ( entry != null )
{
sb.append(entry.getName() + "\t");
byte [] temp = new byte [120];
int leng = 0;
while ( leng != -1 )
{
leng = zip.read(temp);
if ( leng == -1 )
{
break;
}
sb.append(new String(temp, 0, leng));
}
sb.append("\r\n");
}
else
{
flag = false;
}
zip.closeEntry();
}
zip.close();
System.out.println(sb.toString());
}
}