|
Java™ by example!
|
|
|
How do I calculate the checksum of a byte array?
Use the Adler32 class in the java.util.zip package. It contains an implementation of an algorithm to calculate a checksum of an set of bytes. The procedure is simple: create an instance of the Adler32 class, call its method update and provide it with set of bytes in the order they appear in the stream. If all bytes have been processed, call getValue to get the checksum. If you need to calculate checksums of several bytestreams, you can reuse the Adler32 instance but you need to call reset in order to reset it to its original state. Following example displays a checksum of a file provided at command line. Main.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|