Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with CRC in some windows app's whit zip files generated with Java

807580May 5 2010 — edited May 5 2010
Hello,

That is very strange but, we have an app for compressing a folder into a zip. For making, we use the Java.Util.Zip API. Our zip file looks fine, we can unzip the files into another folder without problems, even we can open the file with Winzip or Winrar.

But, we had encountered problems with anothers win apps like "Recovery ToolBox", or another win app built with the "Dynazip.dll" library. This apps give us the next error.

"Bad Crc".

But if we unzip this "corrupt" file and we zip the content again, all work without errors.

[http://img297.imageshack.us/i/dibujoou.jpg/]

Our code (this function only zips a single file):
    public static File zipFile(String sFile, String sNameFileIn, String sFileOut)
            throws IOException {

        File file = new File(sFile);
        FileOutputStream out = new FileOutputStream(sFileOut);
        FileInputStream fin = new FileInputStream(file);

        byte[] fileContent = new byte[(int) file.length()];
        fin.read(fileContent);

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ZipOutputStream zout = new ZipOutputStream(bout);

        ZipEntry zipEntry = new ZipEntry(sNameFileIn);
        zout.putNextEntry(zipEntry);
        zout.write(fileContent, 0, fileContent.length);
        zout.closeEntry();
        zout.finish();
        zout.flush();
        zout.close();

        out.write(bout.toByteArray());
        out.flush();
        out.close();

        File fich = new File(sFileOut);
        fin.close();
        return fich;

    }
I try to calculate the crc number for my own without success... I don't know what's happening

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2010
Added on May 5 2010
5 comments
386 views