日期:2014-05-20 浏览次数:20695 次
public 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<byteArray1.length; i++){ if(byteArray1[i] != byteArray2[i]){ return false; } } } return true; }