import java.io.File;
import java.io.FileInputStream;
public class S12 {
public static void main(String[] args) {
System.out.println(same(new File("e:\\离线壁纸\\3.png"), new File("e:\\离线壁纸\\4.png")));
}
public static boolean same(File a, File b) {
boolean c = false;
if (a.length() == b.length()) {
try (var isa = new FileInputStream(a); var isb = new FileInputStream(b)) {
int num = 0;
while (isa.read() == isb.read()) {
++num;
if (num == a.length()) {
c = true;
break;
}
}
} catch (Exception e) {
}
}
return c;
}
}
使用字节对比判断两个文件是否是同一文件