public static void copyFile(File src, File dest) throws IOException {

        if (src == null)
            throw new NullPointerException("Source must not be null");
        if (dest == null)
            throw new NullPointerException("Destination must not be null");
        if (!src.exists())
            throw new FileNotFoundException("Source '" + src + "' does not exist");
        if (!src.isFile())
            throw new IOException("Source '" + src + "' is not a file");
        if (dest.exists())
            throw new IOException("Destination '" + dest + "' is already exists");

        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(src).getChannel();
            out = new FileOutputStream(dest).getChannel();

            in.transferTo(0, in.size(), out);
        } finally {
            try {
                in.close();
                out.close();
            } catch (IOException e) {
                // Ignore.
            }
        }

        if (src.length() != dest.length()) {
            throw new IOException("Failed to copy full contents from '" +
                src + "' to '" + dest + "'");
        }

        dest.setLastModified(src.lastModified());
    }
public static void copyFile ( File src , File dest ) throws IOException { if ( src == null ) throw new NullPointerException ( "Source must not be null" ) ; if ( dest == null ) throw new NullPointerException ( "Destination must not be null" ) ; if ( ! src . exists ( ) ) throw new FileNotFoundException ( "Source '" + src + "' does not exist" ) ; if ( ! src . isFile ( ) ) throw new IOException ( "Source '" + src + "' is not a file" ) ; if ( dest . exists ( ) ) throw new IOException ( "Destination '" + dest + "' is already exists" ) ; FileChannel in = null , out = null ; try { in = new FileInputStream ( src ) . getChannel ( ) ; out = new FileOutputStream ( dest ) . getChannel ( ) ; in . transferTo ( 0 , in . size ( ) , out ) ; } finally { try { in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { } } if ( src . length ( ) != dest . length ( ) ) { throw new IOException ( "Failed to copy full contents from '" + src + "' to '" + dest + "'" ) ; } dest . setLastModified ( src . lastModified ( ) ) ; }
Copies a file to a new location preserving the file date.

@param src
An existing file to copy, must not be <code>null</code>.
@param dest
The new file, must not be <code>null</code> and exist.

@throws IOException
If copying is failed.