import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;public class ReadZip {
public static void main(String args[]) {
try {
ZipFile zf = new ZipFile("ReadZip.zip");
Enumeration entries = zf.entries(); BufferedReader input = new BufferedReader(new InputStreamReader(
System.in));
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();
System.out.println("Read " + ze.getName() + "?");
String inputLine = input.readLine();
if (inputLine.equalsIgnoreCase("yes")) {
long size = ze.getSize();
if (size > 0) {
System.out.println("Length is " + size);
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
http://www.java2s.com/Code/Java/File-Input-Output/ReadingtheContentsofaZIPFile.htm
搜到的,希望有所帮助
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;public class ReadZip {
public static void main(String args[]) {
try {
ZipFile zf = new ZipFile("ReadZip.zip");
Enumeration entries = zf.entries(); BufferedReader input = new BufferedReader(new InputStreamReader(
System.in));
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();
System.out.println("Read " + ze.getName() + "?");
String inputLine = input.readLine();
if (inputLine.equalsIgnoreCase("yes")) {
long size = ze.getSize();
if (size > 0) {
System.out.println("Length is " + size);
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
http://www.java2s.com/Code/Java/File-Input-Output/ReadingtheContentsofaZIPFile.htm
搜到的,希望有所帮助
try {
ZipFile zf;
zf = new ZipFile(filename);
Enumeration entries = zf.entries();
File name= new File("D:\\2222222222222222222222222222.zip"); BufferedReader input =
new BufferedReader(new FileReader(name));
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();
System.out.println("Read " + ze.getName() + "?");
long size = ze.getSize();
if (size > 0) {
System.out.println("Length is " + size);
BufferedReader br =
new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close(); }
}
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
我改成这样的了,但用不成~
File file = new File("d:\\10.zip");
int leng = 0;
byte[] b = new byte[1024]; String direc = "d:\\";
try {
ZipFile zipfile = new ZipFile(file); ZipInputStream zis = new ZipInputStream(new FileInputStream(file)); for (Enumeration enume = zipfile.entries(); enume.hasMoreElements();) {
ZipEntry entry = (ZipEntry) enume.nextElement();
File temFile = new File(direc + entry.getName());
FileOutputStream fos = new FileOutputStream(temFile);
while ((leng = zis.read(b)) != -1) {
fos.write(b);
}
fos.close();
}
zis.close();
System.out.println(zipfile.getName()); } catch (ZipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }