Я пытаюсь сравнить два файла по блоку. Если блоки равны - получите следующий блок и сравните их. Если конечные блоки равны - верните true; все остальные варианты - вернуть false. Я не понимаю, как правильно выбрать следующий блок и как получить конец файла.Сравнение файлов по блоку (байты) java
private static boolean getBlocks(File file1, File file2, int count) throws IOException {
RandomAccessFile raf1 = new RandomAccessFile(file1, "r");
RandomAccessFile raf2 = new RandomAccessFile(file2, "r");
int point = count * 512;
FileChannel fc1 = raf1.getChannel();
FileChannel fc2 = raf2.getChannel();
MappedByteBuffer buffer1 = fc1.map(FileChannel.MapMode.READ_ONLY, point, 512);
MappedByteBuffer buffer2 = fc2.map(FileChannel.MapMode.READ_ONLY, point, 512);
byte[] bytes1 = new byte[512];
byte[] bytes2 = new byte[512];
buffer1.get(bytes1);
buffer2.get(bytes2);
if (bytes1.length == bytes2.length) {
for (int i = 0; i < bytes1.length; i++) {
if(bytes1[i] != bytes2[i]) {
return false;
}
}
if (true) {
count++;
getBlocks(file1, file2, point);
}
}
buffer1.clear();
buffer2.clear();
return true;
}