简体   繁体   中英

In android, what is the most efficient way to compare two files to determine if they are identical?

When developing in Android, what is the most efficient means of comparing two files to determine if they are identical?

I know calculating the MD5 hashes of each and comparing is one possible solution, but my assumption is that it's quite taxing to do so (and thus multiple comparisons would result in a lot of wait time for the user). I am of course open to correction... my experience when other apps have calculated MD5s is that it's not particularly quick, but perhaps that was their implementation.


The situation being covered is that I have a list of "known" files (identical in name, in separate folders), and a new file. I am trying to determine if the new file is the same as any of my existing files or not.

If you are given 2 random files with no pre-knowledge, the fastest way is to check if the sizes are the same, then check if each byte is the same (stopping when you find one that differs of course).

MD5s help when you know the files ahead of time- when you can pre-calculate the MD5s. It also can help in verifying a file- if you know what the MD5 should be you can compare it to what it actually is to see if a file has been changed/tampered with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM