License Public Domain
Lines 33
Keywords
decompression (2) deflate (1) java (9) zip (5)
Permissions
Owner: monkey103
Viewable by Everyone
Editable by All Siafoo Users
Hide
Know what you're getting – Unlike many sites, all our code is clearly licensed. Join Siafoo Now or Learn More

Unzipping in Java Atom Feed 1

# 's
 1ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile));
2try
3{
4 ZipEntry zipEntry;
5 while ((zipEntry = zipIn.getNextEntry()) != null)
6 {
7 if (zipEntry.isDirectory())
8 {
9 new File(outputDir, zipEntry.getName()).mkdirs();
10 }
11 else
12 {
13 int directoryPrefixIndex = zipEntry.getName().lastIndexOf('/');
14 if (directoryPrefixIndex != -1)
15 {
16 new File(outputDir, zipEntry.getName().substring(0, directoryPrefixIndex)).mkdirs();
17 }
18 BufferedOutputStream fileOut = new BufferedOutputStream(new FileOutputStream(new File(outputDir, zipEntry.getName())));
19 int bytesRead;
20 while ((bytesRead = zipIn.read(inBuffer)) != -1)
21 {
22 fileOut.write(inBuffer, 0, bytesRead);
23 }
24 fileOut.flush();
25 fileOut.close();
26 }
27 zipIn.closeEntry();
28 }
29}
30finally
31{
32 zipIn.close();
33}