I want to compare 2 directory stuctures (only files), so first I’ll get some list of files, with this structure: Filename|size
For ilustration:
(1):
C:\Downloads\100 Java Tips.pdf|1025kB
C:\Downloads\1590599799.rar|1000kB
C:\Downloads\573440.flv|50000kb
C:\Downloads\575492.flv|40000kb
C:\Downloads\avira_antivir_personal_en.exe|15000kB
C:\Downloads\backup-mkyong.com-12-24-2009.tar.gz|2000kB
Then I want to compare 2 directory sturctres = I will have two files with list directory structure (see (1)). One file will be reference the second file will be compared.
I have only tree outcomes:
1)ok – file in first structure exist in second structure with same size
2)fail1 – file in first sturcture doesn´t exist in second
3)fail2 – file in first structure exist in second structure but have diffrent size
My question is, what is best for storing the data what i´ll be comparing?
For example I put the data from file1 to “shelf1” and from file2 to “shelf2”.
Question is what the shelf should be? Array, …
Thanks
If you have the same paths (absolute or relative) you could use a hashmap and use the path as the key and the size (or the corresponding
Fileobject) as the value.Then loop over the entries of map 1 and check if they exist in map 2 and have the same value (i.e. size).