Create Zip File With CRC32 Checksum In Java

Chapter: ZIP Last Updated: 23-04-2016 03:53:14 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class JavaCreateZipFileWithCRC32 {
	public static void main(String args[]) {
		
		String zipFile = "C:/File/Demozip.zip";
		String sourceFile = "C:/File/file1.doc";

		byte[] buffer = new byte[1024];

		try {

			FileOutputStream fout = new FileOutputStream(zipFile);

			CheckedOutputStream checksum = new CheckedOutputStream(fout, new CRC32());

			ZipOutputStream zout = new ZipOutputStream(checksum);

			FileInputStream fin = new FileInputStream(sourceFile);

			zout.putNextEntry(new ZipEntry(sourceFile));

			int length;

			while ((length = fin.read(buffer)) > 0) {
				zout.write(buffer, 0, length);
			}

			zout.closeEntry();

			fin.close();

			zout.close();

			System.out.println("Zip file has been created!");

			System.out.println("CRC32 Checksum is : " + checksum.getChecksum().getValue());
		} catch (IOException ioe) {
			System.out.println("IOException : " + ioe);
		}

	}
}
                /* ............... END ............... */
        

Tags

Create Zip File With CRC32 Checksum, Java

Similar Programs Chapter Last Updated
Zip Entry Is Directory Example In Java ZIP 23-04-2016
Create Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract File With CRC32 Checksum In Java ZIP 23-04-2016
CRC32 Checksum In Java ZIP 10-08-2016
Adler32 Checksum In Java ZIP 23-04-2016
Read Zip File Checksum Value In Java Example ZIP 20-07-2016
Create Checksum For Zip File In Java ZIP 07-08-2017
Decompress Zip File Using ZipInputStream In Java ZIP 20-07-2016
Read Entries In Zip File In Java Example ZIP 20-07-2016
List The Contents Of Zip File In Java Example ZIP 07-08-2017
Extract Contents Of Zip File In Java Example ZIP 07-08-2017
Zip File Creation In Java Example ZIP 23-06-2016

1