File CheckSum





7
Date Submitted Thu. Nov. 17th, 2005 8:43 PM
Revision 1 of 1
Coder mattrmiller
Tags CheckSum | File | Java
Comments 0 comments
File CheckSum
public static String checkSum(String strFile)
        {
                // Declare variables
                CheckedInputStream cCheck = null;
                long lFileSize = 0;
                byte[] bBuf = new byte[1024];

                try
                {
                        // Computer CRC32 checksum
                        cCheck = new CheckedInputStream(new FileInputStream(strFile), new CRC32());

                        // Get file size
                        lFileSize = new File(strFile).length();

                        // Read all file to checksum
                        while (cCheck.read(bBuf) >= 0)
                        {
                        }

                }
                catch (Exception eError)
                {
                        System.err.println("Exception: " + eError);
                        return null;
                }

                return cCheck.getChecksum().toString();
        }

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

There are currently no comments for this snippet.

Voting