Zipping /Unzipp both current directories and subdirectories using zlib java

Hi
Guys any one provide me code for zipping and unzipping directory contains a subdirectories..using zlib java
It is very urgent ..please send me the code..............
consider..
folder name is input for zipping
and zipfile name is input for unzipping..
Please help me out in this problemm
Thanks regards,
javaprabhu

package ar.com.unizono.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
* UnZip -- print or unzip a JAR or PKZIP file using java.util.zip. Command-line
* version: extracts files.
* @author Ian Darwin, [email protected] $Id: UnZip.java,v 1.7 2004/03/07
*         17:40:35 ian Exp $
public class UnZip {
     /** Constants for mode listing or mode extracting. */
     public static final int LIST = 0, EXTRACT = 1;
     /** Whether we are extracting or just printing TOC */
     protected int mode = LIST;
     /** The ZipFile that is used to read an archive */
     protected ZipFile zippy;
     /** The buffer for reading/writing the ZipFile data */
     protected byte[] b;
* Simple main program, construct an UnZipper, process each .ZIP file from
* argv[] through that object.
     public static void main(String[] argv) {
          UnZip u = new UnZip();
          for (int i = 0; i < argv.length; i++) {
               if ("-x".equals(argv)) {
                    u.setMode(EXTRACT);
                    continue;
               String candidate = argv[i];
               // System.err.println("Trying path " + candidate);
               if (candidate.endsWith(".zip") || candidate.endsWith(".jar"))
               u.unZip(candidate);
               else
               System.err.println("Not a zip file? " + candidate);
          System.err.println("All done!");
     /** Construct an UnZip object. Just allocate the buffer */
     UnZip() {
          b = new byte[8092];
     /** Set the Mode (list, extract). */
     protected void setMode(int m) {
          if (m == LIST || m == EXTRACT)
          mode = m;
     /** Cache of paths we've mkdir()ed. */
     protected SortedSet dirsMade;
     /** For a given Zip file, process each entry. */
     public void unZip(String fileName) {
          dirsMade = new TreeSet();
          try {
               zippy = new ZipFile(fileName);
               Enumeration all = zippy.entries();
               while (all.hasMoreElements()) {
                    getFile((ZipEntry) all.nextElement());
          } catch (IOException err) {
               System.err.println("IO Error: " + err);
               return;
     protected boolean warnedMkDir = false;
* Process one file from the zip, given its name. Either print the name, or
* create the file on disk.
     protected void getFile(ZipEntry e) throws IOException {
          String zipName = e.getName();
          switch (mode) {
          case EXTRACT:
               if (zipName.startsWith("/") || zipName.startsWith(File.separatorChar+"")) {
                    if (!warnedMkDir)
                    System.out.println("Ignoring absolute paths");
                    warnedMkDir = true;
                    zipName = zipName.substring(1);
               // if a directory, just return. We mkdir for every file,
               // since some widely-used Zip creators don't put out
               // any directory entries, or put them in the wrong place.
               if (zipName.endsWith("/") || zipName.startsWith(File.separatorChar+"")) {
                    return;
               // Else must be a file; open the file for output
               // Get the directory part.
               int ix = zipName.lastIndexOf('/');
               if(ix==-1)
                    ix=zipName.lastIndexOf(File.separatorChar+"");
               if (ix > 0) {
                    String dirName = zipName.substring(0, ix);
                    if (!dirsMade.contains(dirName)) {
                         File d = new File(dirName);
                         // If it already exists as a dir, don't do anything
                         if (!(d.exists() && d.isDirectory())) {
                              // Try to create the directory, warn if it fails
                              System.out.println("Creating Directory: " + dirName+" at "+d.getAbsolutePath());
                              if (!d.mkdirs()) {
                                   System.err.println("Warning: unable to mkdir "
                                   + dirName);
                              dirsMade.add(dirName);
               System.err.println("Creating " + zipName);
               FileOutputStream os = new FileOutputStream(zipName);
               InputStream is = zippy.getInputStream(e);
               int n = 0;
               while ((n = is.read(b)) > 0)
               os.write(b, 0, n);
               is.close();
               os.close();
               break;
          case LIST:
               // Not extracting, just list
               if (e.isDirectory()) {
                    System.out.println("Directory " + zipName);
               } else {
                    System.out.println("File " + zipName);
               break;
          default:
               throw new IllegalStateException("mode value (" + mode + ") bad");
This version works fine for me but needs enhacements                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • HT3529 I am currently deployed and was using my iMessage to be able to talk to family back in the states and my iMessage stopped working. It will no longer select my number to use as the send/receive. How do I fix this so I can continue to talk to family?

    I am currently deployed and was using my iMessage to be able to talk to family back in the states and my iMessage stopped working. It will no longer select my number to use as the send/receive. How do I fix this so I can continue to talk to family?

    Read here:
    http://support.apple.com/kb/TS2755

  • Problem with getting current date and time using oracle.jbo.domain.Date

    I`d like to get current date and time using oracle.jbo.domain.Date method getCurrentDate(), but it always return current date and 12:00:00. I also need to get the current time.

    I think you should use java.sql.Timestamp domain.
    (And set database type to TIME or DATETIME.)
    Jan

  • TS4268 I've tried the listed troubleshooting procedures to activate Facetime and iMessage, but no luck. Are there any other options? If it helps, I'm currently overseas and only using WiFi to connect.

    I've tried the listed troubleshooting procedures to activate Facetime and iMessage, but no luck. Are there any other options? If it helps, I'm currently overseas and only using WiFi to connect.

        lovethoseleaves,
    Oh no! I am saddened to hear that you are having troubles with your MMS pictures. I know that this can be an important thing to be able to do. I appreciate you working with us to get this matter resolved as well. I see that you have spent time working with us, and I know that can also be frustrating. There are a few things we can check though. Are these to any specific numbers or all? A factory reset certainly should've resolved this. We can check into the account set up as well for that if need be. Please share any additional details that you can think of. Thanks.
    ErinW_VZWSupport
    Follow us on Twitter @VZWSupport

  • Unzipping  zipfile with sub folders...using zlib java

    Hello,
    I am encounterig a problem while unzipping a zipfile using zlib.The zip file contaings subdirectories.so i am not able to unzip the zipfile.Since my code is able to unzip only the files which are in current directory.Please help me out to unzip the subdirectories using zlib.
    Please find my below code..for unzip the files in current directory..
    String destinationname = rootFolder.getAbsolutePath();
    byte[] buf = new byte[1024];
    ZipInputStream zipinputstream = null;
    ZipEntry zipentry;
    zipinputstream = new ZipInputStream(
    new FileInputStream(destinationname+"\\"+date+".zip"));
    zipentry = zipinputstream.getNextEntry();
    while (zipentry != null)
    //for each entry to be extracted
    String entryName = zipentry.getName();
         LoggerHtml.debug(entryName);
         int n;
         FileOutputStream fileoutputstream;
         File newFile = new File(entryName);
         String directory = newFile.getParent();
         if(directory == null)
         //break;
         fileoutputstream = new FileOutputStream(
         entryName);
         while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
         fileoutputstream.write(buf, 0, n);
         fileoutputstream.close();
         zipinputstream.closeEntry();
         zipentry = zipinputstream.getNextEntry();
    Please provide me the coding..It is very urgent...

    google
    code #1
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    public class unzip
        public static void main(String args[])
            if(args.length < 1)
                System.out.println("Syntax : unzip zip-file destination-dir[optional]");
                return;
            try
                ZipFile zf = new ZipFile(args[0]);
                Enumeration zipEnum = zf.entries();
                String dir = new String(".");
                if( args.length == 2 )
                    dir = args[1].replace('\\', '/');
                if(dir.charAt(dir.length()-1) != '/')
                    dir += "/";
                while( zipEnum.hasMoreElements() )
                    ZipEntry item = (ZipEntry) zipEnum.nextElement();
                    if( item.isDirectory() ) //Directory
                        File newdir = new File( dir + item.getName() );
                        System.out.print("Creating directory "+newdir+"..");
                        newdir.mkdir();
                        System.out.println("Done!");
                    else //File
                        String newfile = dir + item.getName();
                        System.out.print("Writing "+newfile+"..");
                        InputStream is = zf.getInputStream(item);
                        FileOutputStream fos = new FileOutputStream(newfile);
                        int ch;
                        while( (ch = is.read()) != -1 )
                            fos.write(ch);
                        is.close();
                        fos.close();
                        System.out.println("Done!");
                zf.close();  
            catch(Exception e)
                System.err.println(e);
    }code #2
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Enumeration;
    import java.util.SortedSet;
    import java.util.TreeSet;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    * UnZip -- print or unzip a JAR or PKZIP file using java.util.zip. Command-line
    * version: extracts files.
    * @author Ian Darwin, [email protected] $Id: UnZip.java,v 1.7 2004/03/07
    *         17:40:35 ian Exp $
    public class UnZip {
      /** Constants for mode listing or mode extracting. */
      public static final int LIST = 0, EXTRACT = 1;
      /** Whether we are extracting or just printing TOC */
      protected int mode = LIST;
      /** The ZipFile that is used to read an archive */
      protected ZipFile zippy;
      /** The buffer for reading/writing the ZipFile data */
      protected byte[] b;
       * Simple main program, construct an UnZipper, process each .ZIP file from
       * argv[] through that object.
      public static void main(String[] argv) {
        UnZip u = new UnZip();
        for (int i = 0; i < argv.length; i++) {
          if ("-x".equals(argv)) {
    u.setMode(EXTRACT);
    continue;
    String candidate = argv[i];
    // System.err.println("Trying path " + candidate);
    if (candidate.endsWith(".zip") || candidate.endsWith(".jar"))
    u.unZip(candidate);
    else
    System.err.println("Not a zip file? " + candidate);
    System.err.println("All done!");
    /** Construct an UnZip object. Just allocate the buffer */
    UnZip() {
    b = new byte[8092];
    /** Set the Mode (list, extract). */
    protected void setMode(int m) {
    if (m == LIST || m == EXTRACT)
    mode = m;
    /** Cache of paths we've mkdir()ed. */
    protected SortedSet dirsMade;
    /** For a given Zip file, process each entry. */
    public void unZip(String fileName) {
    dirsMade = new TreeSet();
    try {
    zippy = new ZipFile(fileName);
    Enumeration all = zippy.entries();
    while (all.hasMoreElements()) {
    getFile((ZipEntry) all.nextElement());
    } catch (IOException err) {
    System.err.println("IO Error: " + err);
    return;
    protected boolean warnedMkDir = false;
    * Process one file from the zip, given its name. Either print the name, or
    * create the file on disk.
    protected void getFile(ZipEntry e) throws IOException {
    String zipName = e.getName();
    switch (mode) {
    case EXTRACT:
    if (zipName.startsWith("/")) {
    if (!warnedMkDir)
    System.out.println("Ignoring absolute paths");
    warnedMkDir = true;
    zipName = zipName.substring(1);
    // if a directory, just return. We mkdir for every file,
    // since some widely-used Zip creators don't put out
    // any directory entries, or put them in the wrong place.
    if (zipName.endsWith("/")) {
    return;
    // Else must be a file; open the file for output
    // Get the directory part.
    int ix = zipName.lastIndexOf('/');
    if (ix > 0) {
    String dirName = zipName.substring(0, ix);
    if (!dirsMade.contains(dirName)) {
    File d = new File(dirName);
    // If it already exists as a dir, don't do anything
    if (!(d.exists() && d.isDirectory())) {
    // Try to create the directory, warn if it fails
    System.out.println("Creating Directory: " + dirName);
    if (!d.mkdirs()) {
    System.err.println("Warning: unable to mkdir "
    + dirName);
    dirsMade.add(dirName);
    System.err.println("Creating " + zipName);
    FileOutputStream os = new FileOutputStream(zipName);
    InputStream is = zippy.getInputStream(e);
    int n = 0;
    while ((n = is.read(b)) > 0)
    os.write(b, 0, n);
    is.close();
    os.close();
    break;
    case LIST:
    // Not extracting, just list
    if (e.isDirectory()) {
    System.out.println("Directory " + zipName);
    } else {
    System.out.println("File " + zipName);
    break;
    default:
    throw new IllegalStateException("mode value (" + mode + ") bad");
    hth

  • Unzip using zlib java

    hello friends,
    Please help me out...iam in urgent help..iam not getting answer for this .. Using zlib java..
    I have a zipfile named prabhu.zip
    It contains
    prabhu\prabhuimage\imagefiles
    right now iam able to unzip only files in current folders..i mean prabhu
    i want to unzip subfolders also...eg prabhuimage folder..
    RIght now only files in current folder is getting unzipped..
    please understand this and help me out my friend..
    Thanks and Regards,
    Prabhu

    hello friends,
    Please help me out...iam in urgent help..iam not getting answer for this .. Using zlib java..
    I have a zipfile named prabhu.zip
    It contains
    prabhu\prabhuimage\imagefiles
    right now iam able to unzip only files in current folders..i mean prabhu
    i want to unzip subfolders also...eg prabhuimage folder..
    RIght now only files in current folder is getting unzipped..
    please understand this and help me out my friend..
    Thanks and Regards,
    Prabhu

  • I used to manage 3 websites using both my imac and macbook, using dropbox, however I can no longer access them from my mac book.

    I have been managing 3 websites using iWeb for the last several years, using both my iMac and Macbook.  However for the last two weeks, I can no longer access these sites from my macbook.  It appears "empty".  When I first started seeing this, I took it to the Genius Bar in another city and he moved some library contents to my desktop - still didin't help.
    I know iWeb is a thing of the past, but I can't stop right now and learn something new for about the next 4 weeks (in a sports team in the middle of a season)
    .  After that, I will have time to learn a new product.
    Also, what is a suggestion for replacing iWeb?  Sandvox? Rapid Weaver?
    Thanks!

    What do you mean when you say you "can no longer access these sites?" Does that mean you can't connect to those sites in your web browser, or that they aren't showing up in iWeb?
    If the latter, note that your iWeb data is all entirely stored in a hidden file. In the Finder, choose Go -> Go To Folder and paste the following path into the window that opens:
    ~/Library/Application Support/iWeb
    In that folder, you will find a single file, called Domain. That's got all the data for all your iWeb sites. If that file is missing, or if it has become corrupt, you will need to restore it from an earlier backup.
    As for replacing iWeb, either Sandvox or RapidWeaver should work. Which works best will depend on your own tastes. Note that neither is capable of fully importing iWeb sites, as those sites will have a lot of content that is copyrighted by Apple. For more information about transitioning to one of these products, see:
    http://rapidweaverfaq.org/site/migrating_from_iWeb.html
    http://www.karelia.com/sandvox/help/z/Transitioning_from_iWeb.html

  • Please describe the directories and subdirectories and their use in .mozilla on linux

    In Linux, the Firefox profile is stored in the .mozilla directory. Under that are the extensions and firefox directories. But under firefox are the profiles directories, crash reports and extensions directories. There appears to be duplicates.
    Also, why isn't Thunderbird, a Mozilla app, also under .mozilla?
    Thank you.

    Fred this is on Linux, not Windows. Also how does that answer the question anyways.
    To actually answer the question, for Thunderbird on Linux it is '''.thunderbird''' if it is not in /.mozilla/thunderbird depending ion whether from mozilla.org or a package provided by Linux distro.
    https://support.mozilla.org/en-US/kb/profiles-tb
    And duplicates of what? as you can create multiple Profiles so there will be a folder for each Profile in .mozilla/firefox/

  • HT1386 simple and easy way to sync my contacts from iPhone 3gs to Macbook Pro that both my partner and I use. Have tried with photos and and only 350 of 3,500 items have synced. Remember simple and easy, I'm still learning-slowly.

    Simple and EASY way to sync contacts from 3gs iPhone to MacBook Pro. Partner and I both use macBook. I have tried and get a message that only 350 of 3,500 item have syncd- all photos. I'm still learning and am very afraid of doing something that will wipe out all info,contacts and photos. Entering this site, the account shows my partners name, but accepts my other information.

    First of all, you should always save you photos on computer like any other digital camera.
    Backup on iCloud or iTunes only backup your Camera Roll. The other photos should be already on the computer.
    Note: Photos are not saved in iTunes, it's only a conduit between your iPhone and your photo managing software on computer.
    What computer do you have?

  • Files, directories and subdirectories count

    Hello,
    I'm currently building a small AIR application via Flash Builder 4 (FLEX 4) that will count the number of files (EVERY type of file)
    in a certain directory (choosen by the user) the problem gets when I have subdirectories,
    tried recursive (which is basicly the only solution) and got stuck and confused with myself, can anyone help a brother out here?
                private var directory:File = File.documentsDirectory;
                [Bindable]
                private var count:int = 0;
                public function browseForDirectory():void
                    directory.browseForDirectory("Select Directory");
                    directory.addEventListener(Event.SELECT, directorySelected);
                public function directorySelected(event:Event):void
                    directory = event.target as File;
                    var files:Array = directory.getDirectoryListing();
                    for(var i:int = 0; i < files.length; i++)
                        myPath.text = directory.nativePath;
                public function countFiles():void
                    var files:Array = directory.getDirectoryListing();
                    for (var i:int = 0; i < files.length ; i++)
                        count++;
                        if (files[i].isDirectory)
                            count += countFiles();
                    myResult.text = count.toString();
    Hoping for a quick response, Thanks!

    Here is how it is done in java as far as file recursion.  The main deficiencies I see with your code is that you don't discriminate if a file is a directory or a file.  You have to discriminate, so that if your file is a directory, you can invoke the "count" function on it.
    http://www.javapractices.com/topic/TopicAction.do?Id=68

  • Can I install Lightroom 5 on both my desktop and laptop using same license?

    I work both at school on my desktop iMac and on my MacBook Pro laptop at home.  Am I able to install the program on both machines using the same license key?

    Yes you can, provided you're the only person using each copy.

  • Install both Windows XP and Vista using boot camp?

    Hi,
    Does anyone know if you can install both vista and xp via bootcamp, so you can boot to either os x, xp or vista?
    Thanks.

    The hatter wrote:
    http://wiki.onmac.net/index.php/TripleBoot_viaBootCamp
    http://macapper.com/forums/showthread.php?t=134
    Ubuntu GRUB
    http://www.ubuntuforums.org/showthread.php?t=233243
    rEFIt:
    http://refit.sourceforge.net/
    Handy for an OSX, Ubuntu, XP triple boot, but not for an OSX, XP, Vista triple boot

  • ITunes on both current iMac and new macbook pro

    I've been searching the forums, but not finding my answer. I have my iMac with my itunes media library. Just got a macbook pro and signed into itunes on the macbook with same itunes user account as I use on the imac. I had some impression all the media from the itunes imac library would mirror over to the macbook. Didnt happen. So do I need to physically copy the media folder from the imac itunes to the macbook itunes media folder to mirror itunes onto the two macs? And what about apps? My main concern are music files and movie/TV files that I want mirrored.
    I was just going to copy the one imac itunes media folder over to the new macbook itunes.
    But wanted to check if anyone had any other suggestions, first.

    If you want to have a copy of the whole iTunes library, keeping your actual settings and everything else, you have to copy the whole "iTunes" folder, on the Music folder, to the MacBook. This will copy everything: apps, music, TV shows, books, etc. If you don't need the settings, just copy the "iTunes Media" folder to the "iTunes" folder of your MacBook.
    You can do this with an external drive > http://support.apple.com/kb/ht1751 (Do the last step on your MacBook)

  • Can I use my itunes with both my iphone and ipad using one computer?

    Can I sync my iphone and ipad on the same computer using itunes installed on the same computer?

    Yes - I sync my iPad, iPhone, and iPod Touch with the same computer / iTunes and haven't had any issues when doing so. The computer's iTunes will recognise the device and what syncing selections you have for it, so you can have different selections of apps, music, films etc on them if you want.

  • Need current data and time stamp in Java mapping

    Hi All,
      I am doing the scenario as file to mail. so here i am using java mappings for sending the file in mail attachment.
      I have done my java mappings and its executed successfully. File is going successfully to third party.
      Business wants date and timestamp in subject line.
    Currently i am using mail subject line as EDI File. 
    But business needs the date and time in the subject line after EDI File as EDI File <yyyymmddhhmm>.
    So my requirement here is adding the date and timestamp.
    Can any one suggest how can write java code to acheive.
    Thanks
    Bhaskar
    Thanks,
    Bhaskar

    Hi Bhaskar,
    >   Business wants date and timestamp in subject line.
    1. Add the import statments at beginning
    import java.util.Date;
    import java.text.SimpleDateFormat;
    2. Add these statments to get timestamp and Concatenate the subject line with string currentdate.
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
    String currentdate = sdf.format(new Date());
    subjectline = subjectline.concat(currentdate);
    Regards,
    Sunil Chandra

Maybe you are looking for