1 | try {↵ | | 1 | try {↵
|
2 | if (!file1.exists() || !file2.exists()) {↵ | | 2 | if (!file1.exists() || !file2.exists()) {↵
|
3 | System.out.println("One or both files do not exist:" + name1 + ", " + name2);↵ | | 3 | System.out.println("One or both files do not exist:" + name1 + ", " + name2);↵
|
4 | return false;↵ | | 4 | return false;↵
|
5 | }↵ | | 5 | }↵
|
|
6 | if (file1.length() != file2.length()) {↵ | | 6 | if (file1.length() != file2.length()) {↵
|
7 | System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +↵ | | 7 | System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +↵
|
8 | name2 + "(" + file2.length() + ")");↵ | | 8 | name2 + "(" + file2.length() + ")");↵
|
9 | return false;↵ | | 9 | return false;↵
|
10 | }↵ | | 10 | }↵
|
|
11 | // byte - byte compare↵ | | 11 | // byte - byte compare↵
|
12 | byte[] buffer1 = new byte[BUF_SIZE];↵ | | 12 | byte[] buffer1 = new byte[BUF_SIZE];↵
|
13 | byte[] buffer2 = new byte[BUF_SIZE];↵ | | 13 | byte[] buffer2 = new byte[BUF_SIZE];↵
|
|
14 | FileInputStream fis1 = new FileInputStream(file1);↵ | | 14 | FileInputStream fis1 = new FileInputStream(file1);↵
|
15 | FileInputStream fis2 = new FileInputStream(file2);↵ | | 15 | FileInputStream fis2 = new FileInputStream(file2);↵
|
16 | int index = 0;↵ | | 16 | int index = 0;↵
|
17 | int read = 0;↵ | | 17 | int read = 0;↵
|
18 | while ((read = fis1.read(buffer1)) != -1) {↵ | | 18 | while ((read = fis1.read(buffer1)) != -1) {↵
|
19 | fis2.read(buffer2);↵ | | 19 | fis2.read(buffer2);↵
|
20 | for (int i = 0; i < read; ++i, ++index) {↵ | | 20 | for (int i = 0; i < read; ++i, ++index) {↵
|
21 | if (buffer1[i] != buffer2[i]) {↵ | | 21 | if (buffer1[i] != buffer2[i]) {↵
|
22 | System.out.println("Bytes mismatch:" + name1 + ", " + name2 +↵ | | 22 | System.out.println("Bytes mismatch:" + name1 + ", " + name2 +↵
|
23 | " at byte " + index);↵ | | 23 | " at byte " + index);↵
|
24 | return false;↵ | | 24 | return false;↵
|
25 | }↵ | | 25 | }↵
|
26 | }↵ | | 26 | }↵
|
27 | }↵ | | 27 | }↵
|
28 | return true;↵ | | 28 | return true;↵
|
29 | }↵ | | 29 | }↵
|
30 | catch (IOException e) {↵ | | 30 | catch (IOException e) {↵
|
31 | System.out.println("IOException comparing files: " + name1 + ", " + name2);↵ | | 31 | System.out.println("IOException comparing files: " + name1 + ", " + name2);↵
|
32 | return false;↵ | | 32 | return false;↵
|
33 | | | 33 |
|