本文共 721 字,大约阅读时间需要 2 分钟。
Java codepublic static boolean testTwoFileIsSame() throws IOException{
String fileName = "D:" + File.separator + "测试.docx";
String fileName1 = "D:" + File.separator + "测试2.docx";
File file1 = new File(fileName);
File file2 = new File(fileName1);
FileInputStream fileStream1 = new FileInputStream(file1);
FileInputStream fileStream2 = new FileInputStream(file2);
byte[] byteArray1 = new byte[(int) file1.length()];
byte[] byteArray2 = new byte[(int) file2.length()];
fileStream1.read(byteArray1);
fileStream2.read(byteArray2);
fileStream1.close();
fileStream2.close();
if(byteArray1.length != byteArray2.length){
return false;
} else{
for(int i = 0; i
if(byteArray1[i] != byteArray2[i]){
return false;
}
}
}
return true;
}
转载地址:http://wbtnx.baihongyu.com/