Is there an easier way to find duplicate files?
Is this seriously the quickest way? I notice some redundancy when you read the FileInputStream into the byte array, and then check each byte. Is there a way to read the file byte-by-byte and check it on-the-fly? It would replace the byte array, to just one byte variable.Code:import java.io.*; public class Test { public static void main(String[] args) throws Throwable { System.out.print(duplicate(new File("C:\\Users\\Me\\Desktop\\4-01 Living the Dream.avi"), new File("C:\\Users\\Me\\Desktop\\4-01 Living the Dream - Copy.avi"))); } public static boolean duplicate(File f1, File f2) throws Throwable { FileInputStream fis1 = new FileInputStream(f1), fis2 = new FileInputStream(f2); byte[] ba1 = new byte[fis1.available()], ba2 = new byte[fis2.available()]; if (ba1.length == ba2.length) { fis1.read(ba1); fis2.read(ba2); for (int i = 0; i < ba1.length; i++) { if (ba1[i] != ba2[i]) return false; } return true; } return false; } }


Reply With Quote
Bookmarks