How to check two text files have the same content or not?
Hi,
I need a method to check two text files whether or not have the same
content. The file is small, about 10 lines. But I don't like to compare
them line by line or jam all lines into one line and compare that line.
I thought there should be some way easier.
I googled and have written the following method. But it does not work
correctly. Even the two files have different content, the method returns
true.
Thank you very much for your help.
/**
* Check two files' content are the same or not. The two files are
allowed to be in different locations. If their
* content inside are the same, return true; otherwise, return false.
* <p>
* Note: is possible that the replacement does not alter the checksum?
*/
public static boolean checkTwoFilesEqual(final File fileA, final
File fileB) throws IOException
{
final CheckedInputStream cisA = new CheckedInputStream(new
FileInputStream(fileA), new CRC32());
final CheckedInputStream cisB = new CheckedInputStream(new
FileInputStream(fileB), new CRC32());
if(cisA.getChecksum().getValue() == cisB.getChecksum().getValue())
{
return true;
}
//not equal
return false;
}