jeremias 2004/03/12 14:21:39
Modified: io/src/java/org/apache/commons/io FileUtils.java
Log:
File copy operations now preserve the file date by default. An additional copyFile
variant enables to disable this feature.
Suggested by: Craig Doremus <craig.at.maine.com> in Bugzilla #27615
Revision Changes Path
1.29 +34 -3 jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java
Index: FileUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- FileUtils.java 12 Mar 2004 21:44:25 -0000 1.28
+++ FileUtils.java 12 Mar 2004 22:21:38 -0000 1.29
@@ -332,6 +332,7 @@
* Copy file from source to destination. If <code>destinationDirectory</code>
does not exist, it
* (and any parent directories) will be created. If a file <code>source</code>
in
* <code>destinationDirectory</code> exists, it will be overwritten.
+ * The copy will have the same file date as the original.
*
* @param source An existing <code>File</code> to copy.
* @param destinationDirectory A directory to copy <code>source</code> into.
@@ -350,13 +351,14 @@
throw new IllegalArgumentException("Destination is not a directory");
}
- copyFile(source, new File(destinationDirectory, source.getName()));
+ copyFile(source, new File(destinationDirectory, source.getName()), true);
}
/**
* Copy file from source to destination. The directories up to
* <code>destination</code> will be created if they don't already exist.
* <code>destination</code> will be overwritten if it already exists.
+ * The copy will have the same file date as the original.
*
* @param source An existing non-directory <code>File</code> to copy
* bytes from.
@@ -370,7 +372,31 @@
* (use [EMAIL PROTECTED] #copyFileToDirectory}).
*/
public static void copyFile(File source, File destination)
- throws IOException {
+ throws IOException {
+ copyFile(source, destination, true);
+ }
+
+
+ /**
+ * Copy file from source to destination. The directories up to
+ * <code>destination</code> will be created if they don't already exist.
+ * <code>destination</code> will be overwritten if it already exists.
+ *
+ * @param source An existing non-directory <code>File</code> to copy
+ * bytes from.
+ * @param destination A non-directory <code>File</code> to write bytes to
+ * (possibly overwriting).
+ * @param preserveFileDate True if the file date of the copy should be the
+ * same as the original.
+ *
+ * @throws IOException if <code>source</code> does not exist,
<code>destination</code> cannot be
+ * written to, or an IO error occurs during copying.
+ *
+ * @throws FileNotFoundException if <code>destination</code> is a directory
+ * (use [EMAIL PROTECTED] #copyFileToDirectory}).
+ */
+ public static void copyFile(File source, File destination, boolean
preserveFileDate)
+ throws IOException {
//check source exists
if (!source.exists()) {
String message = "File " + source + " does not exist";
@@ -409,6 +435,11 @@
+ " to "
+ destination;
throw new IOException(message);
+ }
+
+ if (preserveFileDate) {
+ //file copy should preserve file date
+ destination.setLastModified(source.lastModified());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]