blob: 2b5c1541300ec4a09596efb39811f798560d7e80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/* Unzip.java */
import java.io.*;
import java.util.zip.*;
public class Unzip
{
public static void main(String[] args)
{
if (args.length != 1) {
System.out.println("Usage: java Unzip zipfile");
System.exit(1);
}
try {
byte[] buf = new byte[4096];
ZipInputStream in = new ZipInputStream(
new FileInputStream(args[0]));
while (true) {
//N�chsten Eintrag lesen
ZipEntry entry = in.getNextEntry();
if (entry == null) {
break;
}
//Beschreibung ausgeben
System.out.println(
entry.getName() +
" (" + entry.getCompressedSize() + "/" +
entry.getSize() + ")"
);
//Ausgabedatei erzeugen
FileOutputStream out = new FileOutputStream(
entry.getName()
);
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
//Eintrag schlie�en
in.closeEntry();
}
in.close();
} catch (IOException e) {
System.err.println(e.toString());
}
}
}
|