Want to decompress ZIP file

Hi,
I have a ZIP file that I want to read and decompress into
plain files, how can I do that ?
I've tried to learn how to read in files byte by byte,
is there any faster way?
Thanks,
Alex

the first example doesn't work correctly, here is a fixed version:
      * Unzip a ZIP/JAR file.
      * @param zipFile ZIP/JAR file to extract.
      * @param destinationDir Destination directory to unzip to.
      * @throws IOException
     public static void unzipFile(File zipFile, String destinationDir) throws IOException {
        final int BUFFER = 2048;
        if (zipFile != null && zipFile.exists() && destinationDir != null) {
            ZipInputStream zis = null;
            BufferedOutputStream bos = null;
            try {
                zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile.getAbsoluteFile())));
                ZipEntry entry = null;
                while((entry = zis.getNextEntry()) != null) {
                    if (entry.isDirectory()) { //directory
                        File dir = new File(destinationDir + File.separator + entry.getName());
                        dir.mkdirs();
                    } else { //file
                        int count;
                        byte data[] = new byte[BUFFER];
                        FileOutputStream fos = new FileOutputStream(destinationDir + File.separator + entry.getName());
                        bos = new BufferedOutputStream(fos, BUFFER);
                        while ((count = zis.read(data, 0, BUFFER)) != -1) {
                            bos.write(data, 0, count);
                        bos.flush();
                zis.close();
            } finally {
                if (bos != null) { try { bos.close(); } catch (IOException ioe) { /* ignore */ } }
                if (zis != null) { try { zis.close(); } catch (IOException ioe) { /* ignore */ } }
        }//else: input value unavailable
    }//unzipFile()

Similar Messages

  • Want To create Zip file  using java,And Unzip without Java Program

    I want to create a zip text file using java, I know Using ZipOutputStream , we can create a zip file, , But i want to open that zip file without java program. suppose i use ZipOutputStream , then zip file is created But for unZip also difftrent program require. We cant open that zip file without writing diff java program.
    Actually i have one text file of big size want to create zip file using java , and unzip simply without java program.Its Possible??
    Here is one answer But I want to open that file normal way(
    For Exp. using winzip we can create a zip file and also open simply)
    http://forum.java.sun.com/thread.jspa?threadID=5182691&tstart=0

    Thanks for your Reply,
    I m creating a zip file using this program, Zip file Created successfully But when im trying to open .zip file i m getting error like "Canot open a zip file, it does not appear to be valid Archive"
    import java.io.*;
    import java.util.zip.*;
    public class ZipFileCreation
         public static void main (String argv[])
         try {
         FileOutputStream fos = new FileOutputStream ( "c:/a.zip" );
         ZipOutputStream zip = new ZipOutputStream ( fos );
         zip.setLevel( 9 );
         zip.setMethod( ZipOutputStream.DEFLATED );
    //     get the element file we are going to add, using slashes in name.
         String elementName = "c:/kalpesh/GetSigRoleInfo092702828.txt";
         File elementFile = new File ( elementName );
    //     create the entry
         ZipEntry entry = new ZipEntry( elementName );
         entry.setTime( elementFile.lastModified() );
    //     read contents of file we are going to put in the zip
         int fileLength = (int)elementFile.length();
         System.out.println("fileLength = " +fileLength);
         FileInputStream fis = new FileInputStream ( elementFile );
         byte[] wholeFile = new byte [fileLength];
         int bytesRead = fis.read( wholeFile , 0 /* offset */ , fileLength );
    //     checking bytesRead not shown.
         fis.close();
    //     no need to setCRC, or setSize as they are computed automatically.
         zip.putNextEntry( entry );
    //     write the contents into the zip element
         zip.write( wholeFile , 0, fileLength );
         zip.closeEntry(); System.out.println("Completed");
    //     close the entire zip
         catch(Exception e) {
    e.printStackTrace();
    }

  • Decompress ZIP file with Password

    Hi all,
    Does anybody know how to decompress a ZIP file with password protection?
    I have a decompress code, but I don't know how to insert the pass.
    Any solution?
    Regards

    I'm running out of suggestions over here.
    Your exact command line yields this result:
    zip warning: name not matched: in.txt
    zip error: Nothing to do! (out.zip)
    Well, it should, as I don't have an in.txt. Handing it an existing file, I get this:
    zip -P pass out.zip result.txt
      adding: result.txt (deflated 7%)
    .. and opening in the Finder correctly prompts me:
    so there must be something wrong with your system.
    Very Long Shot: What version do you get when you type this? (I can't imagine this is the actual problem, but you never know.)
    zip --version
    Mine is
    Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
    This is Zip 3.0 (July 5th 2008), by Info-ZIP.
    Currently maintained by E. Gordon.  Please send bug reports to
    the authors using the web page at www.info-zip.org; see README for details.
    Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
    as of above date; see http://www.info-zip.org/ for other sites.
    Compiled with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00) for Unix (Mac OS X) on May 25 2011.

  • Want ProgressBar During Zip File Extraction?

    i have develop a application
    ,in which zip file is extracted
    .(unzipping a zip file),but i want to show progressbar during zip file extract process,i have tried but i am unable to do that.........plz help me?here is my code.......
    ====================
    mxml file->
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initApp()">
    <mx:Script>
    <![CDATA[
    import com.kfc.repflex.utils.ZipExtractComponent;
    import mx.controls.Alert;
    [Bindable]
    private var zip:ZipExtractComponent = null;
    private function initApp():void{
    zip = new ZipExtractComponent("C:/AdobeAIRInstaller.zip");
    ]]>
    </mx:Script>
    <mx:Panel title="Load and extract ZIP files" layout="vertical" horizontalCenter="0" verticalCenter="0" horizontalAlign="center" verticalAlign="middle">
    <mx:Button id="load" label="Load and Extract ZIP" click="zip.loadZIP()"/>
    </mx:Panel>
    </mx:WindowedApplication>
    ====================================
    action script class->
    package com.amdocs.repflex.utils
    import com.amdocs.repflex.utils.zip.*;
    import flash.events.EventDispatcher;
    import flash.filesystem.*;
    import mx.controls.Alert;
    public class ZipExtractComponent extends EventDispatcher
    private var zipInput:File = new File();
    private var zipOutput:File = new File();
    private var zipFile:ZipFile=null;
    private var fileIn:String;
    private var fileOut:String;
    public function ZipExtractComponent(fIn:String){
    this.fileIn=fIn;
    //this.fileOut=fout;
    public function loadZIP():void
    zipInput.nativePath=fileIn;
    var stream:FileStream = new FileStream();
    stream.open(zipInput,FileMode.READ);
    zipFile = new ZipFile(stream);
    extractZip();
    public function extractZip():void
    for(var i:uint = 0; i<zipFile.entries.length; i++)
    var zipEntry:ZipEntry = zipFile.entries[i] as ZipEntry;
    if(!zipEntry.isDirectory())
    //zipOutput.nativePath=fileOut;
    //var targetDir:File = new File("C:/Documents and Settings");
    var targetDir:File = File.documentsDirectory.resolvePath("");
    var entryFile:File = new File();
    entryFile = targetDir.resolvePath(zipEntry.name);
    var entry:FileStream = new FileStream();
    entry.open(entryFile, FileMode.WRITE);
    entry.writeBytes(zipFile.getInput(zipEntry));
    entry.close();
    Alert.show("EXTRACTED SUCCESSFULLY");

    I'm running out of suggestions over here.
    Your exact command line yields this result:
    zip warning: name not matched: in.txt
    zip error: Nothing to do! (out.zip)
    Well, it should, as I don't have an in.txt. Handing it an existing file, I get this:
    zip -P pass out.zip result.txt
      adding: result.txt (deflated 7%)
    .. and opening in the Finder correctly prompts me:
    so there must be something wrong with your system.
    Very Long Shot: What version do you get when you type this? (I can't imagine this is the actual problem, but you never know.)
    zip --version
    Mine is
    Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
    This is Zip 3.0 (July 5th 2008), by Info-ZIP.
    Currently maintained by E. Gordon.  Please send bug reports to
    the authors using the web page at www.info-zip.org; see README for details.
    Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
    as of above date; see http://www.info-zip.org/ for other sites.
    Compiled with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00) for Unix (Mac OS X) on May 25 2011.

  • Best free / cheap software for zipping files?

    Is there any free / cheap software recommended for zipping files that works well with a Mac?

    OS X includes an utility to compress and decompress ZIP files. It's called "Archive Utility" and it's stored on /System/Library/CoreServices, but you have to modify some settings.
    To access to this utility, open a Finder window, select Go menu (on the menu bar) > Go to Folder, and type /System/Library/CoreServices. Then, open "Archive Utility".
    By default, this app compresses files in a CPGZ file, but you can modify this. Go to Archive Utility menu (on the menu bar) > Preferences, and choose "Zip archive" next to "Use archive format".
    Then, to compress files, just close the Preferences window, and go to File menu (on the menu bar) > Create Archive. Finally, choose with the Command key the files you want to compress, and press "Archive", so a ZIP file will be created

  • Error while posting .ZIP file

    Hi All,
    I am working on file to file scenario.. I want to post .zip file from source to target. I am not using any mapping for this... I m using the Integrated configuration for theis scenario.. We are using sFTP advantco adapter for both sender and receiver.
    I am able to post the .zip file with size 50KB only.
    If i send .zip file with more than 50KB size, sender channel picked the file but i am getting the below error in the receiver communication channel.
    Error: Cannot write content to remote file XXXX: Possible causes: SFTP connection is broken or remote file/directory is in use: java.lang.ArrayIndexOutOfBoundsException:  (Software version: 3.0.17)
    How to transfer .zip files with more than 50KB size.
    Thanks,
    Soumya.

    Hi Soumya,
    I see no reason to use sFTP or  advantco for this.
    you can config this scenario using PI regular File adapter, and PI regular File to File scenario.
    in your case you just create an empty DT without fields in Repository, you need to create interfaces (OB,IB) for the Configuration
    this works for me in many scenarios.

  • Un-zip file in Snow Leopard

    How do you un-zip file in Snow Leopard?

    Hey
    Apple used to include a program called StuffIt Expander to decompress zipped files, but doesn’t now that OS X lets you unzip files (but not .sit files). However, StuffIt from SmithMicro Software still comes in handy for opening other types of compressed files, notably the .sit or .sitx compressed types. Go to www.stuffit-expander.com or www.stuffit.com/mac/index.html to download a free version of the software or to splurge for the Deluxe version. In addition to compressing files, StuffIt Deluxe lets you encrypt and back up files.
    Read more: http://www.dummies.com/how-to/content/how-to-zip-and-unzip-files-on-your-mac.htm l#ixzz1KBJk3oib
    Regards,
    Britt.

  • I want to read a file which is in a zip and this zip file is at ftp site

    i am facing this problem and try to find the solution from last month please help me
    i want to read a file which in ziped and this zip file is at ftp site. and i want to read this file without downloading this zip file to local machine. i have to read it from ftp location only

    You can open an URLConnection to a file on an FTP server (search this forum to find out how). You can get the InputStream from the URLConnection and feed it to ZipInputStream. That should do the job.

  • PI FTP get zip file and want to unzip with origin filenames

    Hello everybody,
    we get zip files from ftp and want to unzip this file in one target directory (file adapter). May be, there are more than one file in the zip file, for example test1.txt,test2.txt,test3.txt and zip file name is zipexample.zip. With adapter parameters it is possible to use the name of the zip file, but I've no idea to get the origin filenames (test1.txt, ...).
    I don't want to use the OS Commands to do this.
    I know that's not realy an workitem for PI.
    Is there anyone, who has an idea. Thanks
    Kind regards - Jochen

    Hi,
    Try out this blog
    Working with the PayloadZipBean module of the XI Adapter Framework
    regards,
    venkat.

  • Don't want zip files as attachments

    Sometimes a document such as Word or Excel will appear as a zip in my message when I attach it. I do not want to send a zip file. How can I stop Apple from converting it? I have an iBook G4 with Tiger. Yahoo says they are not doing it, problem is caused by Apple. Note: I have the Apple Microsoft conversion program so my documents are fully workable. Usually I can fix the Word or PDF attaching problem by exporting and saving as a different type of file, but this is not an option for Excel.

    Adam, it does have Show Package Contents.
    As far as I know, it is an Excel file. It is a stand-alone document, consisting of several sheets containing various information - the whole file is a listing of various Scouting organizations, such as packs, troops and posts. But, it is one single file, just with various pages.
    To me, this is not a package.
    But, and this relates to another member's suggestion, the file name does not have a xls suffix. When I try to save it as the file name with xls, I am told it cannot be saved as an Excel file because it is a Numbers file. All I know is when the Scout Office sent it to me, they sent it as an Excel file, and I am able to open, read and edit it because of my Apple-supplied Microsoft converter software.
    I don't know where to go now with this. The only way I can send it back with my changes is to convert it to a PDF file.
    Thanks for any help you and the others can give me.

  • Want to partly unzip a zip file

    I'm trying to upgrade a BIllion 7404 gateway. The relevant firmware is at the top of the list here:
    http://au.billion.com/support/bipac7404vgpm.php
    If my understanding is correct the zip file for the firmware upgrade contains a file within it, a .afw file, that will upgrade the firmware on the Billion. However, when I double click on the zip file, Stuffit unzips the whole lot and I end up with 29 separate files that make up the .afw file, whereas I need the .afw file intact.
    If I put the zip file, call it Upgrade.zip, onto a disk called G5-Data (the name I have given the internal drive on my G5), and use the Terminal command unzip, can anyone tell me the exact command I would need to type in to get a hold of the unzipped .afw file that resides within the zip file?
    Thanks in advance for an suggestions.

    Hi Cole,
    I don't really understand how I got the file, but I got it. The file that I wanted itself contains 29 files that you are not supposed to see. When it is unzipped on a PC, the unzip process stops at the first layer, and that file is recognizable by the gateway as a firmware upgrade file. But if you give the gateway the folder with the 29 files it doesn't know what it is.
    Stuffit reaches into the second layer and unpacks the lot into a folder of 29 files. Must be something in the zip file that is incorrectly setup that allows Stuffit to do that.
    Anyway, I tried the command I posted and up came one file. I found a program called BetterZip that also unzips the file correctly. Maybe there is something wrong with Stuffit 10 and I should give it the boot. Do you know anything about that?
    Thanks again for your help,
    Guy

  • Why do i get a decompression failed notice for downloading zip files

    I'm trying to download my marks for my class and they were posted in a .zip file. however in the downloads box it's telling me that 'decompression failed' and when I try opening it it cannot be opened because it 'is still being downloaded'. I used to be able to open the files, but I don't know what I did.
    I'm new to macs, so it's challenging for me to figure out what the exact problem is, and then to find the solution.
    Thanks for your time!

    Greetings,
    This may be an issue with the specific Zip file you are trying to open (in which case contact your teacher to have them emailed to you separately).
    Make your own Zip file by clicking on any document (like a picture) on the desktop and then go to File > Compress.  Try opening the resulting Zip file and see if it works.  If it works then whatever is going on is with that particular Zip file.  Make sure you are giving the file long enough to download.

  • I have a friend who wants me to zip my iWeb website files so I can send them to him.  I am having difficulty finding where these files are.  Thanks!

    I have a friend who wants me to zip my iWeb website files so I can send them to him.  I am having difficulty finding where these files are.  Thanks!

    Besides the trillion topics that explain where the file is, let me add another one.
    The UNIX way : ~/Library/Application Support/iWeb/
    The Mac way :
    Finder
    Hold Option key
    Pull down GO menu
    Look closely

  • MFT 12.1.3 does not decompress all files when zip file size 2G

    Hi,
    I am having an issue with MFT and SOA. In my setup MFT receives zip files, decompress the zip file into several other files and send them as file reference to a SOA process for further processing. Now I am getting a very large file with a size of around 2 G containing 4 files where the larges file is 5G uncompressed. However when I submit this file to the MFT embedded ftp server MFT moves the file to the payload area, and start decompressing.It stops after compressing the first file. Can't find any error message in the server logs.
    Has somebody seen this kind of behavior?
    Any tip or tricks where to look to find more info about what could be the issue?
    Thanks in advance Frans

    With iPhoto crashing while trying to create a new library makes me think the application may the culprit an you may have to reinstall it. Have you tried the library wihile booted into  Safe Mode?
    Are you able to boot into another user account on your Mac and run iPhoto there?  If so then your home account looks suspicious.
    OT

  • Can't Open (Decompress) any ZIP files all of a sudden!

    Hi
    I've never had problems opening Zip files until a couple of days ago.
    All of a sudden I can't open Zip files from 2 different sources.
    I've tried downloading them in Safari and Firefox.
    I've tried the built in expander and I've tried Stuffit (latest version) and The Unarchiver.
    I keep getting error messages, usually saying the data is corrupted or that it was compressed with an unknown method.
    I got the original file re-sent to me several times (a purchase from a consumer website) with constantly the same result.
    Then today I received a different Zip file from a completely different source with the same result.
    My computer is up to date with all the latest Apple software updates.
    I've tried repairing disc permissions.
    Anyone know of this issue or have any ideas how to fix it?
    Thanks.

    To The Apple Discussion Boards!
    "I've tried repairing disc permissions."
    Did you restart your computer afterwards? If so, download a "zip" file. In the window that pops up, make sure *"Open With"* is selected. Make sure Stuffit Expander is selected or another utility that you want to open all your "zip" files.
    Option: Select +"Do this automatically for files like this from now on."+
    Click the "OK" button.

Maybe you are looking for

  • HP HD 4310 Webcam Sensor

    Hi, I was wondering if anyone could tell me the sensor dimensions for the   HP HD 4310 Webcam they are not quoted in the specifications. If you also know the exact pixel pitch that would be even more helpful. Thanks 

  • How to show  a fixed number of rows in JTable

    Hi, I have to show only a fixed number of rows in the table . After scrolling number of rows must not be changed.

  • Solaris 10 x86 u6

    Hello. Has anyone succeeded in getting Solaris to recognize disks attached in a Dell PowerVault MD1000 connected through a PERC5/E controller? These disks arent found during installation. If anyone could give me some pointers I'd gladly appreciate th

  • Attach to Email - Need to save first?

    Hi All, I just upgraded to Acrobat Pro X. The problem is the following I receive emails via email all day. In Acrobat Pro 7, I could extract the pages I want and re-email with 2 clicks. In Acrobat Pro X,  it seems that when I do the extraction I firs

  • Ralink 2860 Wireless Card

    Hello, with my Ralink 2860 my wireless device has always been identified as ra0 instead of wlan0 and it worked fine. Well with a recent kernel update, my device got switched to being identified as wlan0, and now I have problems connecting to networks