FileDocCategorySizeDatePackage
Compare.javaAPI DocApache log4j 1.2.151945Sat Aug 25 00:09:34 BST 2007org.apache.log4j.util

Compare

public class Compare extends Object

Fields Summary
static final int
B1_NULL
static final int
B2_NULL
Constructors Summary
Methods Summary
public static booleancompare(java.lang.String file1, java.lang.String file2)

  
   
  
         
                                                             
    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;