Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static void main(String[] args) throws Exception {
        String zipname = "d.zip";
        CheckedInputStream checksum = new CheckedInputStream(new FileInputStream(zipname), new Adler32());
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
        ZipEntry entry;

        while ((entry = zis.getNextEntry()) != null) {
            System.out.println("Unzipping: " + entry.getName());
            int size;
            byte[] buffer = new byte[2048];

            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entry.getName()),
                    buffer.length);
            while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                bos.write(buffer, 0, size);
            }
            bos.flush();
            bos.close();
        }

        zis.close();
        System.out.println("Checksum = " + checksum.getChecksum().getValue());
    }
}