Extract File With CRC32 Checksum In Java

Chapter: ZIP Last Updated: 23-04-2016 03:35:16 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class JavaExtractFileWithCRC32 {
	public static void main(String args[]) {

		String filePath = "C:/File/file.zip";

		try {

			FileInputStream fileInputStream = new FileInputStream(filePath);

			CheckedInputStream checksum = new CheckedInputStream(fileInputStream, new CRC32());

			ZipInputStream zin = new ZipInputStream(checksum);

			// get the first entry from the source zip file
			ZipEntry entry = zin.getNextEntry();

			// crate OutputStream to extract the entry from zip file
			OutputStream os = new FileOutputStream("c:/extractedFile.css");

			byte[] buffer = new byte[1024];
			int length;

			// read the entry from zip file and extract it to disk
			while ((length = zin.read(buffer)) > 0) {
				os.write(buffer, 0, length);
			}

			os.close();

			zin.close();

			System.out.println("File Extracted from zip file");

			System.out.println("CRC32 checksum is: " + checksum.getChecksum().getValue());

		} catch (IOException e) {
			System.out.println("IOException :" + e);
		}

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

Tags

Extract 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 CRC32 Checksum 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
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