1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.util;
19
20 import java.io.BufferedReader;
21 import java.io.FileNotFoundException;
22 import java.io.FileReader;
23 import java.io.IOException;
24
25 public class Compare {
26
27 static final int B1_NULL = -1;
28 static final int B2_NULL = -2;
29
30 static
31 public
32 boolean compare(String file1, String file2) throws FileNotFoundException,
33 IOException {
34 BufferedReader in1 = new BufferedReader(new FileReader(file1));
35 BufferedReader in2 = new BufferedReader(new FileReader(file2));
36
37 String s1;
38 int lineCounter = 0;
39 while((s1 = in1.readLine()) != null) {
40 lineCounter++;
41 String s2 = in2.readLine();
42 if(!s1.equals(s2)) {
43 System.out.println("Files ["+file1+"] and ["+file2+"] differ on line "
44 +lineCounter);
45 System.out.println("One reads: ["+s1+"].");
46 System.out.println("Other reads:["+s2+"].");
47 return false;
48 }
49 }
50
51
52 if(in2.read() != -1) {
53 System.out.println("File ["+file2+"] longer than file ["+file1+"].");
54 return false;
55 }
56
57 return true;
58 }
59
60 }