Returns true if the given files exist, are not directories, and contain the same bytes. @throws IOException if an I/O error occurs
(File file1, File file2)
| 369 | * @throws IOException if an I/O error occurs |
| 370 | */ |
| 371 | public static boolean equal(File file1, File file2) throws IOException { |
| 372 | checkNotNull(file1); |
| 373 | checkNotNull(file2); |
| 374 | if (file1 == file2 || file1.equals(file2)) { |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Some operating systems may return zero as the length for files denoting system-dependent |
| 380 | * entities such as devices or pipes, in which case we must fall back on comparing the bytes |
| 381 | * directly. |
| 382 | */ |
| 383 | long len1 = file1.length(); |
| 384 | long len2 = file2.length(); |
| 385 | if (len1 != 0 && len2 != 0 && len1 != len2) { |
| 386 | return false; |
| 387 | } |
| 388 | return asByteSource(file1).contentEquals(asByteSource(file2)); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Atomically creates a new directory somewhere beneath the system's temporary directory (as |