|
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.
|