Compare two files using java
The compareTo method of File class helps us to create a temporary file. This method returns an integer. If the value of the integer is greater than zero, the file will be greater than the argument, if the file is less than zero, the file will be less than the argument and a value of zero means both the files are equal.
import java.io.File;
/**
* File class examples.
*
*/
public class FileExample {
public static void main(String[] args) {
// Create file object representing the source file/directory
File file = new File("d:\\temp\\test.txt");
// Create another file for comparison.
File cFile = new File("d:\\temp\\Copy of test.txtt");
// Compare two files.
int value = file.compareTo(cFile);
System.out.println("File comparison result : "+value);
}
}





















