Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008, 06:17 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Unzipping
Unzipping zip files is fairly easy in Java as shown below.

Code:
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.text.*;

class UnZip {
  public static void main(String args[]) throws IOException {
    InputStream in = 
      new BufferedInputStream(new FileInputStream(args[0]));
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry e;

    while((e=zin.getNextEntry())!= null) {
      if (args.length > 1) {
        if (e.getName().equals(args[1])) {
           unzip(zin, args[1]);
           break;
          }
        }
       unzip(zin, e.getName());
      }
    zin.close();
    }
    
  public static void unzip(ZipInputStream zin, String s) 
     throws IOException {
    System.out.println("unzipping " + s);
    FileOutputStream out = new FileOutputStream(s);
    byte [] b = new byte[512];
    int len = 0;
    while ( (len=zin.read(b))!= -1 ) {
      out.write(b,0,len);
      }
    out.close();
    }
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +2. The time now is 01:39 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org