FileUtils

public final class FileUtils
extends Object

java.lang.Object
   ↳ android.os.FileUtils


Utility methods useful for working with files.

Summary

Nested classes

interface FileUtils.ProgressListener

Listener that is called periodically as progress is made. 

Public methods

static void closeQuietly(AutoCloseable closeable)

Closes the given object quietly, ignoring any checked exceptions.

static void closeQuietly(FileDescriptor fd)

Closes the given object quietly, ignoring any checked exceptions.

static long copy(InputStream in, OutputStream out, CancellationSignal signal, Executor executor, FileUtils.ProgressListener listener)

Copy the contents of one stream to another.

static long copy(FileDescriptor in, FileDescriptor out, CancellationSignal signal, Executor executor, FileUtils.ProgressListener listener)

Copy the contents of one FD to another.

static long copy(FileDescriptor in, FileDescriptor out)

Copy the contents of one FD to another.

static long copy(InputStream in, OutputStream out)

Copy the contents of one stream to another.

Inherited methods

Public methods

closeQuietly

Added in API level 29
public static void closeQuietly (AutoCloseable closeable)

Closes the given object quietly, ignoring any checked exceptions. Does nothing if the given object is null.

Parameters
closeable AutoCloseable: This value may be null.

closeQuietly

Added in API level 29
public static void closeQuietly (FileDescriptor fd)

Closes the given object quietly, ignoring any checked exceptions. Does nothing if the given object is null.

Parameters
fd FileDescriptor: This value may be null.

copy

Added in API level 29
public static long copy (InputStream in, 
                OutputStream out, 
                CancellationSignal signal, 
                Executor executor, 
                FileUtils.ProgressListener listener)

Copy the contents of one stream to another.

Attempts to use several optimization strategies to copy the data in the kernel before falling back to a userspace copy as a last resort.

Parameters
in InputStream: This value must never be null.

out OutputStream: This value must never be null.

signal CancellationSignal: to signal if the copy should be cancelled early. This value may be null.

executor Executor: that listener events should be delivered via. This value may be null.

listener FileUtils.ProgressListener: to be periodically notified as the copy progresses. This value may be null.

Returns
long number of bytes copied.

Throws
IOException

copy

Added in API level 29
public static long copy (FileDescriptor in, 
                FileDescriptor out, 
                CancellationSignal signal, 
                Executor executor, 
                FileUtils.ProgressListener listener)

Copy the contents of one FD to another.

Attempts to use several optimization strategies to copy the data in the kernel before falling back to a userspace copy as a last resort.

Parameters
in FileDescriptor: This value must never be null.

out FileDescriptor: This value must never be null.

signal CancellationSignal: to signal if the copy should be cancelled early. This value may be null.

executor Executor: that listener events should be delivered via. This value may be null.

listener FileUtils.ProgressListener: to be periodically notified as the copy progresses. This value may be null.

Returns
long number of bytes copied.

Throws
IOException

copy

Added in API level 29
public static long copy (FileDescriptor in, 
                FileDescriptor out)

Copy the contents of one FD to another.

Attempts to use several optimization strategies to copy the data in the kernel before falling back to a userspace copy as a last resort.

Parameters
in FileDescriptor: This value must never be null.

out FileDescriptor: This value must never be null.

Returns
long number of bytes copied.

Throws
IOException

copy

Added in API level 29
public static long copy (InputStream in, 
                OutputStream out)

Copy the contents of one stream to another.

Attempts to use several optimization strategies to copy the data in the kernel before falling back to a userspace copy as a last resort.

Parameters
in InputStream: This value must never be null.

out OutputStream: This value must never be null.

Returns
long number of bytes copied.

Throws
IOException