View Single Post
  #18 (permalink)  
Old 01-14-2009, 07:44 PM
Steve11235's Avatar
Steve11235 Steve11235 is offline
Senior Member
 
Join Date: Dec 2008
Posts: 972
Rep Power: 2
Steve11235 is on a distinguished road
Default
So, you want to sort all your files by size. If two files are the same size, you want to compare their contents. If they are identical, you want to list them.


Create a TreeMap<Long, File> and put the file bytes and file into it. This will sort all your files by the number of bytes. You will have to wrap the bytes with Long.

for (File file: myTreeMap.values()) {...} This will loop through all the files in ascending bytes order. You will need a File previousFile variable defined outside the loop and updated inside so you can make comparisons. If the bytes match, then you can compare the contents by opening input streams on the files and doing a byte by byte comparison.
Reply With Quote