Reputation: 2107
I used to think that I can use the checksum (MD5 or CRC32) to improve the uploading method. That is, if the files checksum is the same, I think it's the same file. But one day I saw the code in org.apache.commons.io.FileUtils
which contains two method contentEquals
and contentEqualsIgnoreEOL
. There are two way to check the same file.
if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) {
// same file
return true;
}
and
IOUtils.contentEquals(new FileInputStream(f1), new FileInputStream(f2));
Here are what confused me.
canonical
. What's this meaning?So, in which situation should I use the bytes or checksums to check the same file.
Upvotes: 0
Views: 876
Reputation: 8401
Checksum
Checksum can be used to do quick check by caching the Checksum of each file upfront.
Upvotes: 1