All pastes #548736 Raw Edit

st

public java v1 · immutable
·published 2007-06-07 20:53 UTC
rendered paste body
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.security.MessageDigest;import java.util.ArrayList;import java.util.Formatter;public class MD5Checksum {	public static void main(String[] args) {				MD5Checksum md5checksum = new MD5Checksum();		File file = new File(".");		md5checksum.runthrough(file);			}		public void runthrough(File file)	{						File[] filesInDir = file.listFiles();		for(int i=0; i<filesInDir.length; i++)		{			ArrayList<Integer> al = new ArrayList<Integer>(10000);			File currentFile = filesInDir[i];			if (currentFile.isFile())			{								try {					FileInputStream fis = new FileInputStream(currentFile);					int bit = 0;					while ((bit = fis.read()) != -1)					{						al.add(new Integer(bit));					}					// arraylist -> array				    int size = al.size();					byte[] intArray = new byte[size];				    for(int j=0; j< size; j++)				    {				    	intArray[j] = (byte)al.get(j).intValue();				    }				    					String md5check = getMD5Hash(intArray);					System.out.println(currentFile.getAbsolutePath()+"  : "+md5check);				} catch (FileNotFoundException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}			else				runthrough(currentFile);		}			}		    public String getMD5Hash(byte[] datei) {        StringBuffer result = new StringBuffer(32);        try {            MessageDigest md5 = MessageDigest.getInstance("MD5");            md5.update(datei);            Formatter f = new Formatter(result);            for (byte b : md5.digest()) {                f.format("%02x", b);            }        } catch (Exception ex) {            ex.printStackTrace();        }        return result.toString();    }            }