Language

Files.Copy Method

Definition

Overloads

Name Description
Copy(IPath, Stream)

Copies all bytes from a file to an output stream.

Copy(IPath, IPath, ICopyOption[])

Copy a file to a target file.

Copy(Stream, IPath, ICopyOption[])

Copies all bytes from an input stream to a file.

Copy(IPath, Stream)

Copies all bytes from a file to an output stream.

[Android.Runtime.Register("copy", "(Ljava/nio/file/Path;Ljava/io/OutputStream;)J", "", ApiSince=26)]
public static long Copy(Java.Nio.FileNio.IPath? source, System.IO.Stream? out);
[<Android.Runtime.Register("copy", "(Ljava/nio/file/Path;Ljava/io/OutputStream;)J", "", ApiSince=26)>]
static member Copy : Java.Nio.FileNio.IPath * System.IO.Stream -> int64

Parameters

source
IPath

the path to the file

out
Stream

the output stream to write to

Returns

the number of bytes read or written

Attributes

Remarks

Copies all bytes from a file to an output stream.

If an I/O error occurs reading from the file or writing to the output stream, then it may do so after some bytes have been read or written. Consequently the output stream may be in an inconsistent state. It is strongly recommended that the output stream be promptly closed if an I/O error occurs.

This method may block indefinitely writing to the output stream (or reading from the file). The behavior for the case that the output stream is asynchronously closed or the thread interrupted during the copy is highly output stream and file system provider specific and therefore not specified.

Note that if the given output stream is java.io.Flushable then its java.io.Flushable#flush flush method may need to invoked after this method completes so as to flush any buffered output.

Java documentation for java.nio.file.Files.copy(java.nio.file.Path, java.io.OutputStream).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Copy(IPath, IPath, ICopyOption[])

Copy a file to a target file.

[Android.Runtime.Register("copy", "(Ljava/nio/file/Path;Ljava/nio/file/Path;[Ljava/nio/file/CopyOption;)Ljava/nio/file/Path;", "", ApiSince=26)]
public static Java.Nio.FileNio.IPath? Copy(Java.Nio.FileNio.IPath? source, Java.Nio.FileNio.IPath? target, params Java.Nio.FileNio.ICopyOption[]? options);
[<Android.Runtime.Register("copy", "(Ljava/nio/file/Path;Ljava/nio/file/Path;[Ljava/nio/file/CopyOption;)Ljava/nio/file/Path;", "", ApiSince=26)>]
static member Copy : Java.Nio.FileNio.IPath * Java.Nio.FileNio.IPath * Java.Nio.FileNio.ICopyOption[] -> Java.Nio.FileNio.IPath

Parameters

source
IPath

the path to the file to copy

target
IPath

the path to the target file (may be associated with a different provider to the source path)

options
ICopyOption[]

options specifying how the copy should be done

Returns

the path to the target file

Attributes

Exceptions

if the array contains a copy option that is not supported

if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)

the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory (optional specific exception)

if an I/O error occurs

In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the source file, the checkWrite method is invoked to check write access to the target file. If a symbolic link is copied the security manager is invoked to check LinkPermission("symbolic").

Remarks

Java documentation for java.nio.file.Files.copy(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption...).

Java reference for java.nio.file.Files.copy.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Copy(Stream, IPath, ICopyOption[])

Copies all bytes from an input stream to a file.

[Android.Runtime.Register("copy", "(Ljava/io/InputStream;Ljava/nio/file/Path;[Ljava/nio/file/CopyOption;)J", "", ApiSince=26)]
public static long Copy(System.IO.Stream? in, Java.Nio.FileNio.IPath? target, params Java.Nio.FileNio.ICopyOption[]? options);
[<Android.Runtime.Register("copy", "(Ljava/io/InputStream;Ljava/nio/file/Path;[Ljava/nio/file/CopyOption;)J", "", ApiSince=26)>]
static member Copy : System.IO.Stream * Java.Nio.FileNio.IPath * Java.Nio.FileNio.ICopyOption[] -> int64

Parameters

in
Stream

The stream that supplies the bytes to copy to the target file.

target
IPath

the path to the file

options
ICopyOption[]

options specifying how the copy should be done

Returns

the number of bytes read or written

Attributes

Exceptions

if an I/O error occurs when reading or writing

if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)

the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory (optional specific exception)

if options contains a copy option that is not supported

In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file. Where the REPLACE_EXISTING option is specified, the security manager's checkDelete method is invoked to check that an existing file can be deleted.

Remarks

Java documentation for java.nio.file.Files.copy(java.io.InputStream, java.nio.file.Path, java.nio.file.CopyOption...).

Java reference for java.nio.file.Files.copy.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to