欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java计算文件的CRC-32冗余校验,javacrc-32冗余校验,package cn.o

来源: javaer 分享于  点击 35466 次 点评:98

java计算文件的CRC-32冗余校验,javacrc-32冗余校验,package cn.o


package cn.outofmemory.snippets.core;import java.io.IOException;import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;public class CalculateCRC32ChecksumOfZipEntry {    public static void main(String[] args) {        ZipFile zipFile = null;        try {            // open a zip file for reading            zipFile = new ZipFile("c:/archive.zip");            // get an enumeration of the ZIP file entries            Enumeration<? extends ZipEntry> e = zipFile.entries();            while (e.hasMoreElements()) {                ZipEntry entry = e.nextElement();                // get the name of the entry                String entryName = entry.getName();                // get the CRC-32 checksum of the uncompressed entry data, or -1 if not known                long crc = entry.getCrc();                System.out.println(entryName + " with CRC-32: " + crc);            }        }        catch (IOException ioe) {            System.out.println("Error opening zip file" + ioe);        }         finally {             try {                 if (zipFile!=null) {                     zipFile.close();                 }             }             catch (IOException ioe) {                    System.out.println("Error while closing zip file" + ioe);             }         }    }}
相关栏目:

用户点评