日期:2014-05-20  浏览次数:20695 次

java判断word是否相等?????
java两次读取同一个word文件成二进制流,然后在比对这个二进制流。是否会相等啊!~

------解决方案--------------------
Java code
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;
    }