JDK-6469152 : File.copyTo(File) to simply copy a file to specified directory
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-09-11
  • Updated: 2011-02-16
  • Resolved: 2009-02-16
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
It would be incredibly nice to have a copyTo feature added to the File (Java.io.File) class that function like this:

File file = new File("the directory");
File fileDest = new File("the destination directory");
file.copyTo(fileDest);

That would be very very good for all of us developers

JUSTIFICATION :
it would drastically shorten code lengths and also make the programming process much better

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
make a copy of the selected file and paste it in the specified directory
ACTUAL -
see above^

---------- BEGIN SOURCE ----------
import java.io.File;

try
{
      File file = new File("the directory");
      File fileDest = new File("the destination directory");
      file.copyTo(fileDest);
   }
catch(Exception e)
   {
      System.err.println("Error!");
   }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
write a really long unneccessary code i guess....

Comments
EVALUATION This feature has been addressed by the new file system API defined by JSR-203. In particular, it defines the Path#copyTo method to copy a source file to a target file. The sample directory contains sample copy for copy directories (or a complete file tree).
11-09-2006