Cannot use winzip to unzip the zip file zipped by java.util.zip

Hi all,
I use the followcode to create a zip file, and i downlaod it and try to use winzip to unzip this file but fail. The path is correct and i got the zip file. but it just cannot unzip.
pls help
thanks alot.
Kin
          int count = 0;
          count = ContentDocuments.size();
          for (int i = 0; i < bb; i++)     {
               System.out.println(filenames[i] + "");
          // Create a buffer for reading the files
          byte[] buf = new byte[10*1024*1024];
          try {      
               String outFilename = MyDir + "zipfile/" + getContentID2()+".zip";
               System.out.println("outFilename = " + outFilename);
               ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
               for (int i=0; i<filenames.length; i++) {           
                    FileInputStream in = new FileInputStream(filenames);
                    out.putNextEntry(new ZipEntry(filenames[i]));
                    int len;
                    while ((len = in.read(buf)) != -1) {               
                         out.write(buf, 0, len);
                    out.closeEntry();
                    in.close();
               out.close();
          } catch (IOException e)     {
               System.err.println("zipprocess " + e.getMessage());

I've written a replacement zip file creator class. Not much tested but it seems to work, however I've yet to try it with the version of WINZIP that rejected my previous attempts. Oh, and the stored dates are garbage.
* ZipOutputFile.java
* Created on 25 March 2004, 13:08
package zip;
import java.io.IOException;
import java.nio.ByteBuffer;
* <p>Creates a ZIP archive in a file which WINZIP should be able to read.</p>
* <p>Unfortunately zip archives generated by the standard Java class
* {@link java.util.zip.ZipOutputStream}, while adhering to PKZIPs format specification,
* don't appear to be readable by some versions of WinZip and similar utilities. This is
* probably because they use
* a format specified for writing to a non-seakable stream, where the length and CRC of
* a file is writen to a special block following the data. Since the length of the binary
* date is unknown this makes an archive quite complicated to read, and it looks like
* WinZip hasn't bothered.</p>
* <p>All data is Deflated. Close completes the archive, flush terminates the current entry.</p>
* @see java.util.zip.ZipOutputStream
* @author  Malcolm McMahon
public class ZipOutputFile extends java.io.OutputStream {
    byte[] oneByte = new byte[1];
    java.io.RandomAccessFile archive;
    public final static short DEFLATE_METHOD = 8;
    public final static short VERSION_CODE = 20;
    public final static short MIN_VERSION = 10;
    public final static int  ENTRY_HEADER_MAGIC = 0x04034b50;
    public final static int  CATALOG_HEADER_MAGIC = 0x02014b50;
    public final static int  CATALOG_END_MAGIC = 0x06054b50;
    private final static short DISC_NUMBER = 0;
    ByteBuffer entryHeader = ByteBuffer.wrap(new byte[30]);
    ByteBuffer entryLater = ByteBuffer.wrap(new byte[12]);
    java.util.zip.CRC32 crcAcc = new java.util.zip.CRC32();
    java.util.zip.Deflater def = new java.util.zip.Deflater(java.util.zip.Deflater.DEFLATED, true);
    int totalCompressed;
    long MSEPOCH;
    byte [] deflateBuf = new byte[2048];
    public static final long SECONDS_TO_DAYS = 60 * 60 * 24;
     * Entry stores info about each file stored
    private class Entry {
        long offset;        // position of header in file
        byte[] name;
        long crc;
        int compressedSize;
        int uncompressedSize;
        java.util.Date date;
         * Contructor also writes initial header.
         * @param fileName Name under which data is stored.
         * @param date  Date to label the file with
         * @TODO get the date stored properly
        public Entry(String fileName, java.util.Date date) throws IOException {
            name = fileName.getBytes();
            this.date = date == null ? new java.util.Date() : date;
            entryHeader.position(10);
            putDate(entryHeader);
            entryHeader.putShort(26, (short)name.length);
            offset = archive.getFilePointer();
            archive.write(entryHeader.array());
            archive.write(name);
            catalog.add(this);
            crcAcc.reset();
            totalCompressed = 0;
            def.reset();
         * Finish writing entry data. Save the lenghts & crc for catalog
         * and go back and fill them in in the entry header.
        public void close() throws IOException {
            def.finish();
            while(!def.finished())
                deflate();
            entryLater.position(0);
            crc = crcAcc.getValue();
            compressedSize = totalCompressed;
            uncompressedSize = def.getTotalIn();
            entryLater.putInt((int)crc);
            entryLater.putInt(compressedSize);
            entryLater.putInt(uncompressedSize);
            long eof = archive.getFilePointer();
            archive.seek(offset + 14);
            archive.write(entryLater.array());
            archive.seek(eof);
         * Write the catalog data relevant to this entry. Buffer is
         * preloaded with fixed data.
         * @param buf Buffer to organise fixed lenght part of header
        public void writeCatalog(ByteBuffer buf) throws IOException {
            buf.position(12);
            putDate(buf);
            buf.putInt((int)crc);
            buf.putInt(compressedSize);
            buf.putInt(uncompressedSize);
            buf.putShort((short)name.length);
            buf.putShort((short)0);  // extra field length
            buf.putShort((short)0);  // file comment length
            buf.putShort(DISC_NUMBER);  // disk number
            buf.putShort((short)0); // internal attributes
            buf.putInt(0);      // external file attributes
            buf.putInt((int)offset); // file position
            archive.write(buf.array());
            archive.write(name);
         * This writes the entries date in MSDOS format.
         * @param buf Where to write it
         * @TODO Get this generating sane dates
        public void putDate(ByteBuffer buf) {
            long msTime = (date.getTime() - MSEPOCH) / 1000;
            buf.putShort((short)(msTime % SECONDS_TO_DAYS));
            buf.putShort((short)(msTime / SECONDS_TO_DAYS));
    private Entry entryInProgress = null; // entry currently being written
    private java.util.ArrayList catalog = new java.util.ArrayList(12);  // all entries
     * Start a new output file.
     * @param name The name to store as
     * @param date Date - null indicates current time
    public java.io.OutputStream openEntry(String name, java.util.Date date) throws IOException{
        if(entryInProgress != null)
            entryInProgress.close();
        entryInProgress = new Entry(name, date);
        return this;
     * Creates a new instance of ZipOutputFile
     * @param fd The file to write to
    public ZipOutputFile(java.io.File fd) throws IOException {
        this(new java.io.RandomAccessFile(fd, "rw"));
     * Create new instance of ZipOutputFile from RandomAccessFile
     * @param archive RandomAccessFile
    public ZipOutputFile(java.io.RandomAccessFile archive) {
        this.archive = archive;
        entryHeader.order(java.nio.ByteOrder.LITTLE_ENDIAN);  // create fixed fields of header
        entryLater.order(java.nio.ByteOrder.LITTLE_ENDIAN);
        entryHeader.putInt(ENTRY_HEADER_MAGIC);
        entryHeader.putShort(MIN_VERSION);
        entryHeader.putShort((short)0);  // general purpose flag
        entryHeader.putShort(DEFLATE_METHOD);
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.clear();
        cal.set(java.util.Calendar.YEAR, 1950);
        cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
//        def.setStrategy(Deflater.HUFFMAN_ONLY);
        MSEPOCH = cal.getTimeInMillis();
     * Writes the master catalogue and postamble and closes the archive file.
    public void close() throws IOException{
        if(entryInProgress != null)
            entryInProgress.close();
        ByteBuffer catEntry = ByteBuffer.wrap(new byte[46]);
        catEntry.order(java.nio.ByteOrder.LITTLE_ENDIAN);
        catEntry.putInt(CATALOG_HEADER_MAGIC);
        catEntry.putShort(VERSION_CODE);
        catEntry.putShort(MIN_VERSION);
        catEntry.putShort((short)0);
        catEntry.putShort(DEFLATE_METHOD);
        long catStart = archive.getFilePointer();
        for(java.util.Iterator it = catalog.iterator(); it.hasNext();) {
            ((Entry)it.next()).writeCatalog(catEntry);
        catEntry.position(0);
        catEntry.putInt(CATALOG_END_MAGIC);
        catEntry.putShort(DISC_NUMBER);
        catEntry.putShort(DISC_NUMBER);
        catEntry.putShort((short)catalog.size());
        catEntry.putShort((short)catalog.size());
        catEntry.putInt((int)(archive.getFilePointer() - catStart));
        catEntry.putInt((int)catStart);
        catEntry.putShort((short)0);
        archive.write(catEntry.array(), 0, catEntry.position());
        archive.setLength(archive.getFilePointer());  // truncate if old file
        archive.close();
        def.end();
     * Closes entry in progress.
    public void flush() throws IOException{
        if(entryInProgress == null)
            throw new IllegalStateException("Must call openEntry before writing");
        entryInProgress.close();
        entryInProgress = null;
     * Standard write routine. Defined by {@link java.io.OutputStream}.
     * Can only be used once openEntry has defined the file.
     * @param b  Bytes to write
    public void write(byte[] b) throws IOException{
        if(entryInProgress == null)
            throw new IllegalStateException("Must call openEntry before writing");
        crcAcc.update(b);
        def.setInput(b);
        while(!def.needsInput())
            deflate();
     * Standard write routine. Defined by {@link java.io.OutputStream}.
     * Can only be used once openEntry has defined the file.
     * @param b  Bytes to write
    public void write(int b) throws IOException{
        oneByte[0] = (byte)b;
        crcAcc.update(b);
        write(oneByte, 0, 1);
     *  Standard write routine. Defined by {@link java.io.OutputStream}.
     * Can only be used once openEntry has defined the file.
     * @param b  Bytes to write
     * @param off Start offset
     * @param len Byte count
    public void write(byte[] b, int off, int len) throws IOException{
        if(entryInProgress == null)
            throw new IllegalStateException("Must call openEntry before writing");
        crcAcc.update(b, off, len);
        def.setInput(b, off, len);
        while(!def.needsInput())
            deflate();
    * Gets a buffer full of coded data from the deflater and writes it to archive.
    private void deflate() throws IOException {
        int len = def.deflate(deflateBuf);
        totalCompressed += len;
        if(len > 0)
            archive.write(deflateBuf, 0, len);

Similar Messages

  • Cannot extract Zip file with Winzip after zipping with java.util.zip

    Hi all,
    I write a class for zip and unzip the text files together which can be zip and unzip successfully with Java platform. However, I cannot extract the zip file with Winzip or even WinRAR after zipping with Java platform.
    Please help to comment, thanks~
    Below is the code:
    =====================================================================
    package myapp.util;
    import java.io.* ;
    import java.util.TreeMap ;
    import java.util.zip.* ;
    import myapp.exception.UserException ;
    public class CompressionUtil {
      public CompressionUtil() {
        super() ;
      public void createZip(String zipName, String fileName)
          throws ZipException, FileNotFoundException, IOException, UserException {
        FileOutputStream fos = null ;
        BufferedOutputStream bos = null ;
        ZipOutputStream zos = null ;
        File file = null ;
        try {
          file = new File(zipName) ; //new zip file
          if (file.isDirectory()) //check if it is a directory
         throw new UserException("Invalid zip file ["+zipName+"]") ;
          if (file.exists() && !file.canWrite()) //check if it is readonly
         throw new UserException("Zip file is ReadOnly ["+zipName+"]") ;
          if (file.exists()) //overwrite the existing file
         file.delete();
          file.createNewFile();
          //instantiate the ZipOutputStream
          fos = new FileOutputStream(file) ;
          bos = new BufferedOutputStream(fos) ;
          zos = new ZipOutputStream(bos) ;
          this.writeZipFileEntry(zos, fileName); //call to write the file into the zip
          zos.finish() ;
        catch (ZipException ze) {
          throw ze ;
        catch (FileNotFoundException fnfe) {
          throw fnfe ;
        catch (IOException ioe) {
          throw ioe ;
        catch (UserException ue) {
          throw ue ;
        finally {
          //close all the stream and file
          if (fos != null)
         fos.close() ;
          if (bos != null)
         bos.close();
          if (zos != null)
         zos.close();
          if (file != null)
         file = null ;
        }//end of try-catch-finally
      private void writeZipFileEntry(ZipOutputStream zos, String fileName)
          throws ZipException, FileNotFoundException, IOException, UserException {
        BufferedInputStream bis = null ;
        File file = null ;
        ZipEntry zentry = null ;
        byte[] bArray = null ;
        try {
          file = new File(fileName) ; //instantiate the file
          if (!file.exists()) //check if the file is not exist
         throw new UserException("No such file ["+fileName+"]") ;
          if (file.isDirectory()) //check if the file is a directory
         throw new UserException("Invalid file ["+fileName+"]") ;
          //instantiate the BufferedInputStream
          bis = new BufferedInputStream(new FileInputStream(file)) ;
          //Get the content of the file and put into the byte[]
          int size = (int) file.length();
          if (size == -1)
         throw new UserException("Cannot determine the file size [" +fileName + "]");
          bArray = new byte[(int) size];
          int rb = 0;
          int chunk = 0;
          while (((int) size - rb) > 0) {
         chunk = bis.read(bArray, rb, (int) size - rb);
         if (chunk == -1)
           break;
         rb += chunk;
          }//end of while (((int)size - rb) > 0)
          //instantiate the CRC32
          CRC32 crc = new CRC32() ;
          crc.update(bArray, 0, size);
          //instantiate the ZipEntry
          zentry = new ZipEntry(fileName) ;
          zentry.setMethod(ZipEntry.STORED) ;
          zentry.setSize(size);
          zentry.setCrc(crc.getValue());
          //write all the info to the ZipOutputStream
          zos.putNextEntry(zentry);
          zos.write(bArray, 0, size);
          zos.closeEntry();
        catch (ZipException ze) {
          throw ze ;
        catch (FileNotFoundException fnfe) {
          throw fnfe ;
        catch (IOException ioe) {
          throw ioe ;
        catch (UserException ue) {
          throw ue ;
        finally {
          //close all the stream and file
          if (bis != null)
         bis.close();
          if (file != null)
         file = null ;
        }//end of try-catch-finally
    }

    Tried~
    The problem is still here~ >___<
    Anyway, thanks for information sharing~
    The message is:
    Cannot open file: it does not appear to be a valid archive.
    If you downloaded this file, try downloading the file again.
    The problem may be here:
    if (fos != null)
    fos.close() ;
    if (bos != null)
    bos.close();
    if (zos != null)
    zos.close();
    if (file != null)
    file = null ;
    The fos is closed before bos so the last buffer is not
    saved.
    zos.close() is enough.

  • IOException java.util.zip.ZipException: error in opening zip file

    Hi Folks,
    In my application one Zip file will be placed in the server. to unzip that zip file i have used java.util.Zip.
    It is working fine.but some times it gets the following error.
    **IOException java.util.zip.ZipException: error in opening zip file**
    why is it so? but very rarely. I couldnt identify the exact scenario, where it causes the problem.
    Normally that zip file contains set of images of customer.
    Please share your inputs.
    Thanks,
    Balu.

    Thanks for ur reply.
    EJB is not used in my application.
    VC++ application at customer side prepares the zip file, and it will upload that zip to te server using ftp.
    After uploading done, at the server end one java program(contains main function) will access that folder to unzip.
    Thanks,
    Balu.

  • Create Zip File In Windows and Extract Zip File In Linux

    I had created a zip file (together with directory) under Windows as follow (Code are picked from [http://www.exampledepot.com/egs/java.util.zip/CreateZip.html|http://www.exampledepot.com/egs/java.util.zip/CreateZip.html] ) :
    package sandbox;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    * @author yan-cheng.cheok
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            // These are the files to include in the ZIP file
            String[] filenames = new String[]{"MyDirectory" + File.separator + "MyFile.txt"};
            // Create a buffer for reading the files
            byte[] buf = new byte[1024];
            try {
                // Create the ZIP file
                String outFilename = "outfile.zip";
                ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
                // Compress the files
                for (int i=0; i<filenames.length; i++) {
                    FileInputStream in = new FileInputStream(filenames);
    // Add ZIP entry to output stream.
    out.putNextEntry(new ZipEntry(filenames[i]));
    // Transfer bytes from the file to the ZIP file
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    // Complete the entry
    out.closeEntry();
    in.close();
    // Complete the ZIP file
    out.close();
    } catch (IOException e) {
    e.printStackTrace();
    The newly created zip file can be extracted without problem under Windows, by using  [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html]
    However, I realize if I extract the newly created zip file under Linux, using modified version of  [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html] . The original version doesn't check for directory using zipEntry.isDirectory()).public static boolean extractZipFile(File zipFilePath, boolean overwrite) {
    InputStream inputStream = null;
    ZipInputStream zipInputStream = null;
    boolean status = true;
    try {
    inputStream = new FileInputStream(zipFilePath);
    zipInputStream = new ZipInputStream(inputStream);
    final byte[] data = new byte[1024];
    while (true) {
    ZipEntry zipEntry = null;
    FileOutputStream outputStream = null;
    try {
    zipEntry = zipInputStream.getNextEntry();
    if (zipEntry == null) break;
    final String destination = Utils.getUserDataDirectory() + zipEntry.getName();
    if (overwrite == false) {
    if (Utils.isFileOrDirectoryExist(destination)) continue;
    if (zipEntry.isDirectory())
    Utils.createCompleteDirectoryHierarchyIfDoesNotExist(destination);
    else
    final File file = new File(destination);
    // Ensure directory is there before we write the file.
    Utils.createCompleteDirectoryHierarchyIfDoesNotExist(file.getParentFile());
    int size = zipInputStream.read(data);
    if (size > 0) {
    outputStream = new FileOutputStream(destination);
    do {
    outputStream.write(data, 0, size);
    size = zipInputStream.read(data);
    } while(size >= 0);
    catch (IOException exp) {
    log.error(null, exp);
    status = false;
    break;
    finally {
    if (outputStream != null) {
    try {
    outputStream.close();
    catch (IOException exp) {
    log.error(null, exp);
    break;
    if (zipInputStream != null) {
    try {
    zipInputStream.closeEntry();
    catch (IOException exp) {
    log.error(null, exp);
    break;
    } // while(true)
    catch (IOException exp) {
    log.error(null, exp);
    status = false;
    finally {
    if (zipInputStream != null) {
    try {
    zipInputStream.close();
    } catch (IOException ex) {
    log.error(null, ex);
    if (inputStream != null) {
    try {
    inputStream.close();
    } catch (IOException ex) {
    log.error(null, ex);
    return status;
    *"MyDirectory\MyFile.txt" instead of MyFile.txt being placed under folder MyDirectory.*
    I try to solve the problem by changing the zip file creation code to
    +String[] filenames = new String[]{"MyDirectory" + "/" + "MyFile.txt"};+
    But, is this an eligible solution, by hard-coded the seperator? Will it work under Mac OS? (I do not have a Mac to try out)
    p/s To be honest, I do a cross post at  [http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux|http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux] Just want to get more opinion on this.
    Edited by: yccheok on Apr 26, 2010 11:41 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Your solution lies in the File.separator constant; this constant will contain the path separator that is used by the operating system. No need to hardcode one, Java already has it.
    edit: when it comes to paths by the way, I have the bad habit of always using the front slash ( / ). This will also work under Windows and has the added benefit of not needing to be escaped.

  • Java.util.zip.ZipException Error

    I created a jar file, and put in C:\tools
    C:\tools>java -jar myjar.jar is working fine
    However, if I try to run myjar.jar in other directories, then I have problems.
    I already set the classpath:
    SET CLASSPATH=.;%CLASSPATH%;C:\tools\myjar.jar;
    Here's the error. Any ideas???
    C:\>java -jar myjar.jar
    Exception in thread "main" java.util.zip.ZipException: The system cannot find th
    e file specified
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:112)
    at java.util.jar.JarFile.<init>(JarFile.java:117)
    at java.util.jar.JarFile.<init>(JarFile.java:55)

    You always need to specify a proper file name when you use the -jar switch. If you are not in c:\tools you have to run with "java -jar c:\tools\myjar.jar".
    Setting the classpath in particular doesn't help becuase the file name given to the -jar switch will override all settings for classpath. http://java.sun.com/j2se/1.4/docs/tooldocs/findingclasses.html#userclass
    But since you now have myjar.jar in your classpath, you can run the application from any directory with "java your.main.ClassName" :)

  • Running JAR gives me java.util.zip.ZipException

    I just made a JAR--we'll call it MyApp.jar--containing some classes in the JAR's main directory (that is, not in any subfolder, just in the top level), and the following manifest that I put in from a text file i called "MANIFEST.MF":
    "Main-Class: MyApp (i also tried using "MyApp.class")
    Class-Path: smartjcommon_1.6.jar smartjprint_1.5.6.jar smartjprint_demo.jar
    Those JARs in the class-path are three JAR files in the same directory as MyApp.jar that are used as external libraries for my program. I go to the command prompt, go to the directory with these JARs, and type in:
    java -jar MyApp (i also tried adding -window at the end, as I've seen done, since it's a Swing program)
    and I get:
    Exception in thread "main" java.util.zip.ZipException: The system cannot find the file specified
    at java.util.zip.ZipFile.open(Native Method)
    etc etc
    I'm sure it's a very simple problem, but what am I doing wrong?

    You aren't spelling the name of the jar file correctly. Tryjava -jar MyApp.jarinstead.

  • Java.util.zip.ZipException: invalid entry size error --  help required

    Hi all
    I am sure this error would have been posted many number of times, but I would really appreciate if someone could help me with my problem. I am working on reading data from a .zip file, which in it has ~5GB data. All I am performing is a read operation through the piece of code specified below. This code worked well for .zip files handling till ~2.5GB
    FileInputStream fis = new FileInputStream(filename);
    BufferedInputStream bis = new BufferedInputStream(fis);
    ZipInputStream zis = new ZipInputStream(bis);
    StreamTokenizer tok = new StreamTokenizer( zis );
    ZipEntry entry;
    while((entry = zis.getNextEntry()) != null)
    \\read from the zip file through the streamTokenizer
    I just print what I read through the program, on the console.
    But the error I get is
    java.util.zip.ZipException: invalid entry size (expected 4294967295 but got 2117536490 bytes)
    at java.util.zip.ZipInputStream.readEnd(Unknown Source)
    at java.util.zip.ZipInputStream.read(Unknown Source)
    at java.util.zip.InflaterInputStream.read(Unknown Source)
    at java.io.StreamTokenizer.read(Unknown Source)
    at java.io.StreamTokenizer.nextToken(Unknown Source)
    at ZipFileStreams.getMessages(ZipFileStreams.java:677)
    at ZipFileStreams.main(ZipFileStreams.java:814)
    Could anybody give me hints as to what am I missing and where am i going wrong. Any help would be appreciated.
    Thanks

    Hi,
    I get the same exception while reading a ZIP file. The size if the ZIP file is just 82KB but I am reading it over FTP not sure if it makes any difference. I am using JDK 1.4.2_05. Here is the code I am trying to execute.
    public class TestFTP {
    public static void main( String[] argv ) throws Exception {
    String inboundPath = "/transfer/inbound/";
    FTPClient ftp = new FTPClient();
    ftp.connect("123");
    ftp.login( "123", "123" );
    ftp.changeWorkingDirectory(inboundPath);
    FTPFile[] zipFiles = ftp.listFiles("*.zip");
    TelnetClient telnetClient;
    for(int i=0;i<zipFiles.length;i++){   
    System.out.println(zipFiles.getName());
    ZipInputStream zis = new ZipInputStream(ftp.retrieveFileStream(zipFiles[i].getName()));
    for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()){           
    System.out.println(entry.getName());
    The error message is
    java.util.zip.ZipException: invalid entry size (expected 10291 but got 10233 bytes)
         at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:367)
         at java.util.zip.ZipInputStream.read(ZipInputStream.java:141)
         at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:91)
         at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:69)
         at test.TestFTP.main(TestFTP.java:41)
    Exception in thread "main"
    Please let me know if you were able to fix the problem.
    Thanks

  • Java.util.Zip Exception

    Hi All
    I am trying to deploy an ear which contains a session
    bean .I have added some jars to the ear which are required  for the hibernate.
    At the time of the deploying i am getting the follwing
    error
    Please giude me to solve this problem
    Thanks and Regards
    Satyam
    10/09/02 05:35:58 -  EAR file uploaded to server for 2781ms.
    10/09/02 05:43:12 -  ERROR: Not deployed. Deploy Service returned ERROR:
                         java.rmi.RemoteException: Error while getting the internal libraries of application sap.com/SampleHibernateEar in operation deploy..
                         Reason: The system cannot find the file specified; nested exception is:
                              java.util.zip.ZipException: The system cannot find the file specified
                              at com.sap.engine.services.deploy.server.DeployServiceImpl.deploy(DeployServiceImpl.java:478)
                              at com.sap.engine.services.deploy.server.DeployServiceImplp4_Skel.dispatch(DeployServiceImplp4_Skel.java:1555)
                              at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:294)
                              at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:183)
                              at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:119)
                              at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
                              at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
                              at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
                              at java.security.AccessController.doPrivileged(Native Method)
                              at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
                              at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)
                         Caused by: java.util.zip.ZipException: The system cannot find the file specified
                              at java.util.zip.ZipFile.open(Native Method)
                              at java.util.zip.ZipFile.<init>(ZipFile.java:112)
                              at java.util.jar.JarFile.<init>(JarFile.java:127)
                              at java.util.jar.JarFile.<init>(JarFile.java:65)
                              at com.sap.engine.services.deploy.ear.jar.EARReader.getAdditionalLibrariesEntries(EARReader.java:788)
                              at com.sap.engine.services.deploy.server.application.DeployUtilTransaction.commonBegin(DeployUtilTransaction.java:281)
                              at com.sap.engine.services.deploy.server.application.DeploymentTransaction.begin(DeploymentTransaction.java:296)
                              at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:290)
                              at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhases(ApplicationTransaction.java:323)
                              at com.sap.engine.services.deploy.server.DeployServiceImpl.makeGlobalTransaction(DeployServiceImpl.java:3033)
                              at com.sap.engine.services.deploy.server.DeployServiceImpl.deploy(DeployServiceImpl.java:463)
                              ... 10 more
                         For detailed information see the log file of the Deploy Service.
    10/09/02 05:43:12 -  ***********************************************************
    Sep 2, 2010 5:43:12 AM   Info: End of log messages of the target system.
    Sep 2, 2010 5:43:12 AM   Info: ***** End of SAP J2EE Engine Deployment (J2EE Application) *****
    Sep 2, 2010 5:43:12 AM   Error: Aborted: development component 'SampleHibernateEar'/'sap.com'/'localhost'/'2006.09.01.17.09.15':
    Caught exception during application deployment from SAP J2EE Engine's deploy service:
    java.rmi.RemoteException: Error while getting the internal libraries of application sap.com/SampleHibernateEar in operation deploy..
    Reason: The system cannot find the file specified; nested exception is:
         java.util.zip.ZipException: The system cannot find the file specified
    (message ID: com.sap.sdm.serverext.servertype.inqmy.extern.EngineApplOnlineDeployerImpl.performAction(DeploymentActionTypes).REMEXC)
    Sep 2, 2010 5:43:12 AM   Info: J2EE Engine is in same state (online/offline) as it has been before this deployment process.
    Sep 2, 2010 5:43:12 AM   Error: -
    At least one of the Deployments failed -

    Hi Satya,
    Does your EAR contain EJB jar from EJB project? You can try to open EAR file with zip and check.
    Best regards, Maksim Rashchynski.

  • Java.lang.Error: java.util.zip.ZipException: The system cannot find the fil

    I got maven 221 installed
    i got jdk 1.6 and 1.5 installed (have tested both)
    I have a strange error. All my co-workers can build but I cant. The only thing I can find is that I dont have installed BEA Weblogic but I dont want to have that installed. It should be able to run anyway.
    Could someone tell me what is wrong? If you need pom.xml I got that one as well.
    process-classes:
    [copy] Copying 4 files to C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content
    [mkdir] Created dir: C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-jar
    [java] Creating an MJF from the contents of directory C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content...
    [java] Compiling the files...
    [java] Creating the list.
    [java] Doing the compile.
    [java] WLMaker-SubProcess: : Exception in thread "main" java.lang.Error: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:93)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.main(BeanGenDriver.java:117)
    [java] WLMaker-SubProcess: : Caused by: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.open(Native Method)
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.<init>(ZipFile.java:203)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:132)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:97)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:90)
    [java] WLMaker-SubProcess: :      ... 1 more
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] BeanGen code generation failed
    [HUDSON] Archiving C:\hudson\jobs\albpm_ip-identity-asserter_-Build\workspace\pom.xml to C:\hudson\jobs\albpmip-identity-asserter_-Build\modules\dk.skat.ip.integration.albpm$ip-identity-asserter\builds\2010-11-2213-41-28\archive\dk.skat.ip.integration.albpm\ip-identity-asserter\1.2\pom.xml
    [INFO] ------------------------------------------------------------------------

    from my experience, using weblogic jars can be a pain if the full install is not on the local box.
    Note that you dont have to 'install' it. Just copy the directory.
    Reason is that the jar files have manifests with relative classpaths.
    For an example of horror take a look at the weblogic.jar MANIFEST's classpath entry.
    -Fred

  • How do I estimate time takes to Zip/Unzip using java.util.zip ?

    If I am compressing files or uncompressing zips using java.util.zip is there a way for me to tell the user how long it should take or for perhaps displaying a progress monitor ?

    For unzip use the ZipInputStream and pass it a CountingInputStream that keeps track ofr the number of bytes read from it (you write this). This CountingInputStream extends fileInputStream and as such can provide you with information about the total number of bytes available to be read and the number already read. This can give a crude idea of how much work has been done and how much work still needs to be done. It is inaccurate but should be good enoough for a progress bar
    As for zipping use the ZipOutputStream and pass it blocks of information. Keep track of the number of blocks you have written and the number you still need to write.
    matfud

  • How to get the entries in a jar/zip file contained within a jar/zip file?

    If I want to list the jar/zip entries in a jar/zip file contained within a jar/zip file how can I do that?
    In order to get to the entry enumeration I need a Zip/JarFile:
    ZipFile zip = new ZipFile("C:/java_dev/Java_dl/java_jdk_commander_v36d.zip");
    // Process the zip file. Close it when the block is exited.
    try {
    // Loop through the zip entries and print the name of each one.
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    finally {
    zip.close();
    Zip file "java_jdk_commander_v36d.zip" contains two zip entries:
    1) UsersGuide.zip
    2) JDKcommander.exe
    How to list the entries in "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip"?
    The following code:
    URL url = new URL("jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip");
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    zipFile = (ZipFile)jarConnection.getJarFile();
    would point to "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip", which is no help at all and Class JarURLConnection does not have an enumeration method.
    How can I do this?
    Thanks.
    Andre

    I'm not sure I understand the problem. The difference between a zip and jar file is the manifest file; JarFile is extended from ZipFile and is able to read the manifest, other than that they are the same. Your code
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    }is close to what I've use for a jar, below. Why not use the same approach? I don't understand what you're trying to do by using JarURLConnection - it's usually used to read the jar contents.
    String jarName = "";
    JarFile jar = null;
    try
        jar = new JarFile(jarName);
    catch (IOException ex)
        System.out.println("Unable to open jarfile" + jarName);
        ex.printStackTrace();
    for ( Enumeration en = jar.entries() ;  en.hasMoreElements() ;)
        System.out.println(en.nextElement());
    }

  • Cannot find acsbackup_instance.log in the backup file

    hi,
    I had ACS 5.2 ( Evalution License ) setup installed on VMware with patch 11 when I try to restore earlier backup of ACS gives me  error "Cannot find acsbackup_instance.log in the backup file"
    I am using Filezilla FTP sever for backup transfer.
    suggest... Thanks in advance..
    Regards,
    Avi.

    That is strange!! Just make sure you are using the TFTP and not the DESK in the repository. It looks to me that you are trying to restore from the DESK and not the TFTP and it could not find the backup file int he DESK.
    If you double check the repository and you are 100% sure that the TFTP is being used then I would recommend to open a TAC case and feedback us about what the issue was if the TAC discovered the root cause of this.
    btw, what you see if you apply this command on CLI:
    show backup history
    Thanks.
    Amjad
    Rating useful replies is more useful than saying "Thank you"

  • Zipping files in a folder using java.util.zip

    hi guys,
    does any body has the java code for
    zipping files in a folder
    hi guys,
    actually i want to zip no of files in a folder .the folder can also have sub folder
    and after zipping when i extract the files manually i should
    maintain the same folder structure
    does any body has the code
    please reply me soon its a bit urgent

    hi smeee
    i tried running ur code but its not working
    here the command
    java c:\abc\ zzz.zip
    its saying
    no files or directories even though there's the
    directory present
    what's the solution Hi,
    Oops that was because of the error check added at the last moment..
    Anyway, You need to use the following command to run it :
    java ZipUtility c:\abc c:\zzz.zip
    Please use the following corrected code:
         Class to zip file(s).
         Requires jdk1.3.1.
         To run use the following command:
         java ZipUtility <directory or file to be zipped> <name of zip file to be created>
         Please specify absolute path names as its parameters while running this program.
    import java.util.zip.*;
    import java.io.*;
    public class ZipUtility {
         ZipOutputStream cpZipOutputStream = null;
         String strSource = "";
         String strTarget = "";
         String strSubstring = "";
         public static void main(String args[]) {
              if(     args == null || args.length < 2) {
                   System.out.println("Usage: java ZipUtility <directory or file to be zipped> <name of zip file to be created>");
                   return;
              ZipUtility udZipUtility = new ZipUtility();
              udZipUtility.strSource = args[0];
              udZipUtility.strTarget = args[1];
              udZipUtility.zip();
         private void zip(){
                        try
                             File cpFile = new File (strSource);
                             if (!cpFile.isFile() && !cpFile.isDirectory() ) {
                                  System.out.println("\nSource file/directory Not Found!");
                                  return;
                             if  (cpFile.isDirectory()) {
                                  strSubstring = strSource;;
                             } else {
                                  strSubstring = "";
                             cpZipOutputStream = new ZipOutputStream(new FileOutputStream(strTarget));
                             cpZipOutputStream.setLevel(9);
                             zipFiles( cpFile);
                             cpZipOutputStream.finish();
                             cpZipOutputStream.close();
                             System.out.println("\n Finished creating zip file " + strTarget + " from source " + strSource);
                        }catch (Exception e){
                             e.printStackTrace();
         private void  zipFiles(File cpFile) {
                   if (cpFile.isDirectory()) {
                        File [] fList = cpFile.listFiles() ;
                        for (int i=0; i< fList.length; i++){
                             zipFiles(fList) ;
                   } else {
                        try {
                             String strAbsPath = cpFile.getAbsolutePath();
                             String strZipEntryName ="";
                             if (!strSubstring.equals("") ){
                                  strZipEntryName = strAbsPath.substring(strSource.length()+1, strAbsPath.length());
                             } else {
                                  strZipEntryName = cpFile.getName();
                             byte[] b = new byte[ (int)(cpFile.length()) ];
                             FileInputStream cpFileInputStream = new FileInputStream (cpFile) ;
                             int i = cpFileInputStream.read(b, 0, (int)cpFile.length());
                             ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
                             cpZipOutputStream.putNextEntry(cpZipEntry );
                             cpZipOutputStream.write(b, 0, (int)cpFile.length());
                             cpZipOutputStream.closeEntry() ;
                        } catch (Exception e) {
                             e.printStackTrace();

  • "You cannot use this version of the application Mail with this version...

    I recently needed to replace my hard drive and now when I try to open the Mail application I get the following message: "You cannot use this version of the application Mail with this version of Mac OS X."
    Any help is appreciated.

    ANSWERING MY OWN POST:
    I have tried reinstalling Mail from my Snow Leopard upgrade disk directly and tried it using Pacifist. Neither worked because both simply reinstalled version 4.0. Fortunately, I have a MacBook Pro and it has version 4.1. I copied this directly, which was not ideal (it was quite confused about my mailboxes), but it worked.
    The problem is that +Software Update+ did not detect the old version of Mail and Apple does not provide a direct way (that I could find) of downloading the latest version. Each time I downloaded Mail from Apple, it was version 4.0.

  • Itunes cannot run because some of the required files are missing?

    This morning when I turned on my computer my itunes was suddenly not working. When I double click the desktop icon to open it up, I get an error message that reads:
    iTunes cannot run because some of the required files are missing. Please reinstall iTunes.
    I searched the FAQ archive and still cannot find an answer to my problem.
    THe last part of the error message says to reinstall itunes, but I cannot even get the corrupt version off. Is there anyway to save the music I have on here? Another user and I have separate iTUnes music, so a great deal of music will be lost, including things recently purchased.

    Thank you so very much. I don't know why I didn't think of that but it is up and running fine now

Maybe you are looking for