// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;

public class FileDiff {
    public static boolean identical(String fnm1, String fnm2) throws IOException {
        long flen1 = (new File(fnm1)).length();
        long flen2 = (new File(fnm2)).length();
        if(flen1 != flen2) return false;
        InputStream is1 = new FileInputStream(fnm1);
        InputStream is2 = new FileInputStream(fnm2);
        byte[] b1 = new byte[100000];
        byte[] b2 = new byte[100000];
        for(;;) {
            int n1 = is1.read(b1);
            int n2 = is2.read(b2);
            if(n1 != n2) return false;
            if(n1 < 0) break;
            for(int i = 0; i < n1; i++) if(b1[i] != b2[i]) return false;
        }
        return true;
    }
    public static void main(String[] args) throws Exception {
        System.out.println(identical("C:\\a.jpg", "C:\\b.jpg"));
        System.out.println(identical("C:\\b.jpg", "C:\\b.jpg"));
    }
}
