Comparing two files for exact match

java junit
// you could choose another way to read them // "Files.readAllBytes" is Java 8 byte[] file1Bytes = Files.readAllBytes(Paths.get("path/to/file")); byte[] file2Bytes = Files.readAllBytes(Paths.get("path/to/file")); String file1 = new String(file1, StandardCharsets.UTF_8); String file2 = new String(file2, StandardCharsets.UTF_8); assertEquals("Files don't match", file1, file2);

In case you have the Apache Commons IO

assertEquals(FileUtils.checksumCRC32(file1), FileUtils.checksumCRC32(file2));

Reference

No known

History May 17, 2017