copyTo

fun InputStream.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long(source)

Copies this stream to the given output stream, returning the number of bytes copied

Note It is the caller's responsibility to close both of these resources.

Since Kotlin

1.0

fun Reader.copyTo(out: Writer, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long(source)

Copies this reader to the given out writer, returning the number of characters copied.

Note it is the caller's responsibility to close both of these resources.

Since Kotlin

1.0

Return

number of characters copied.

Parameters

out

writer to write to.

bufferSize

size of character buffer to use in process.


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

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.

Since Kotlin

1.0

Return

the target file.

Parameters

overwrite

true if destination overwrite is allowed.

bufferSize

the buffer size to use when copying.

Throws

if the source file doesn't exist.

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

if any errors occur while copying.