zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java 对文件进行 CRC32 校验详解编程语言

JAVA文件编程语言 详解 进行 校验 CRC32
2023-06-13 09:20:30 时间
* ----------------------------------------------------------------------------- * Used to provide an example of how to calculate the checksum of a file using * the CRC-32 checksum engine. * @version 1.0 * @author Jeffrey M. Hunter ([email protected]) * @author a href="http://www.idevelopment.info" http://www.idevelopment.info * ----------------------------------------------------------------------------- public class ChecksumCRC32 { private static void doChecksum(String fileName) { try { CheckedInputStream cis = null; long fileSize = 0; try { // Computer CRC32 checksum cis = new CheckedInputStream( new FileInputStream(fileName), new CRC32()); fileSize = new File(fileName).length(); } catch (FileNotFoundException e) { System.err.println("File not found."); System.exit(1); byte[] buf = new byte[128]; while(cis.read(buf) = 0) { long checksum = cis.getChecksum().getValue(); System.out.println(checksum + " " + fileSize + " " + fileName); } catch (IOException e) { e.printStackTrace(); System.exit(1);
* Sole entry point to the class and application. * @param args Array of String arguments. public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: java ChecksumCRC32 filename"); } else { doChecksum(args[0]); }

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10898.html

cjava