Internal copy file method. @param srcFile the validated source file, not null @param destFile the validated destination file, not null @param preserveFileDate whether to preserve the file date @throws IOException if an error occurs
(File srcFile, File destFile, boolean preserveFileDate)
| 445 | * @throws IOException if an error occurs |
| 446 | */ |
| 447 | private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { |
| 448 | if (destFile.exists() && destFile.isDirectory()) { |
| 449 | throw new IOException("Destination '" + destFile + "' exists but is a directory"); |
| 450 | } |
| 451 | |
| 452 | try (FileInputStream input = new FileInputStream(srcFile)) { |
| 453 | try (FileOutputStream output = new FileOutputStream(destFile)) { |
| 454 | IO.copy(input, output); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if (srcFile.length() != destFile.length()) { |
| 459 | throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); |
| 460 | } |
| 461 | if (preserveFileDate) { |
| 462 | destFile.setLastModified(srcFile.lastModified()); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Unconditionally close an <code>Reader</code>. |