集册 Java实例教程 使用Adler32校验和提取Zip文件

使用Adler32校验和提取Zip文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

461
使用Adler32校验和提取Zip文件

 

import java.io.FileInputStream;

import java.io.FileOutputStream;/**from N o w J a v a . c o m - 时代Java**/

import java.io.IOException;

import java.io.OutputStream;

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[])

        {

               

                String sourceZipFile = "C:/Folder/sourceFile.zip";

               

                try

                {

                        //create FileInputStream from the source zip file

                        FileInputStream fin = new FileInputStream(sourceZipFile);

                       
                       /*
                       来 自*
                        n o w  j a v a  . c o m
                       */

                        CheckedInputStream checksum = new CheckedInputStream(fin,new Adler32());

                         

                        ZipInputStream zin = new ZipInputStream(checksum);

                       

                        ZipEntry entry = zin.getNextEntry();

                       

                        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(
展开阅读全文