Skip to content

Commit e590959

Browse files
committed
Added a copyFileToDirectory(File, File, boolean) variant. No unit test as the lastModified checking part of the current tests is not being tested currently (it wasn't reliable). This is mentioned in #IO-104
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@484861 13f79535-47bb-0310-9956-ffa450edef68
1 parent 808b5eb commit e590959

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/java/org/apache/commons/io/FileUtils.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,35 @@ public static URL[] toURLs(File[] files) throws IOException {
480480
* @see #copyFile(File, File, boolean)
481481
*/
482482
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException {
483+
copyFileToDirectory(srcFile, destDir, true);
484+
}
485+
486+
/**
487+
* Copies a file to a directory optionally preserving the file date.
488+
* <p>
489+
* This method copies the contents of the specified source file
490+
* to a file of the same name in the specified destination directory.
491+
* The destination directory is created if it does not exist.
492+
* If the destination file exists, then this method will overwrite it.
493+
*
494+
* @param srcFile an existing file to copy, must not be null
495+
* @param destDir the directory to place the copy in, must not be null
496+
* @param preserveFileDate true if the file date of the copy
497+
* should be the same as the original
498+
*
499+
* @throws NullPointerException if source or destination is null
500+
* @throws IOException if source or destination is invalid
501+
* @throws IOException if an IO error occurs during copying
502+
* @see #copyFile(File, File, boolean)
503+
*/
504+
public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws IOException {
483505
if (destDir == null) {
484506
throw new NullPointerException("Destination must not be null");
485507
}
486508
if (destDir.exists() && destDir.isDirectory() == false) {
487509
throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
488510
}
489-
copyFile(srcFile, new File(destDir, srcFile.getName()), true);
511+
copyFile(srcFile, new File(destDir, srcFile.getName()), preserveFileDate);
490512
}
491513

492514
/**

0 commit comments

Comments
 (0)