copyTo

JVM
1.0
fun File.copyTo(
    target: File,
    overwrite: Boolean = false,
    bufferSize: Int = DEFAULT_BUFFER_SIZE
): File

Copies this file to the given target file.

If some directories on a way to the target are missing, then they will be created. If the target file already exists, this function will fail unless overwrite argument is set to true.

When overwrite is true and target is a directory, it is replaced only if it is empty.

If this file is a directory, it is copied without its content, i.e. an empty target directory is created. If you want to copy directory including its contents, use copyRecursively.

The operation doesn't preserve copied file attributes such as creation/modification date, permissions, etc.

Parameters

overwrite - true if destination overwrite is allowed.

bufferSize - the buffer size to use when copying.

Exceptions

NoSuchFileException - if the source file doesn't exist.

FileAlreadyExistsException - if the destination file already exists and overwrite argument is set to false.

IOException - if any errors occur while copying.

Return the target file.