BufferedReader in1 = new BufferedReader(new FileReader(file1));
BufferedReader in2 = new BufferedReader(new FileReader(file2));
String s1;
int lineCounter = 0;
while((s1 = in1.readLine()) != null) {
lineCounter++;
String s2 = in2.readLine();
if(!s1.equals(s2)) {
System.out.println("Files ["+file1+"] and ["+file2+"] differ on line "
+lineCounter);
System.out.println("One reads: ["+s1+"].");
System.out.println("Other reads:["+s2+"].");
return false;
}
}
// the second file is longer
if(in2.read() != -1) {
System.out.println("File ["+file2+"] longer than file ["+file1+"].");
return false;
}
return true;