Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/os/FileUtils#nestedclasses) \| [Methods](https://developer.android.com/reference/android/os/FileUtils#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/FileUtils#inhmethods)

# FileUtils

*** ** * ** ***


`
public

final

class
FileUtils
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.FileUtils |

<br />

*** ** * ** ***

Utility methods useful for working with files.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/os/FileUtils.ProgressListener` Listener that is called periodically as progress is made. |

| ### Public methods ||
|---|---|
| ` static void` | ` https://developer.android.com/reference/android/os/FileUtils#closeQuietly(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor fd) ` *This method was deprecated in API level 30. This method may suppress potentially significant exceptions, particularly when closing writable resources. With a writable resource, a failure thrown from `close()` should be considered as significant as a failure thrown from a write method because it may indicate a failure to flush bytes to the underlying resource.* |
| ` static void` | ` https://developer.android.com/reference/android/os/FileUtils#closeQuietly(java.lang.AutoCloseable)(https://developer.android.com/reference/java/lang/AutoCloseable closeable) ` *This method was deprecated in API level 30. This method may suppress potentially significant exceptions, particularly when closing writable resources. With a writable resource, a failure thrown from `close()` should be considered as significant as a failure thrown from a write method because it may indicate a failure to flush bytes to the underlying resource.* |
| ` static long` | ` https://developer.android.com/reference/android/os/FileUtils#copy(java.io.InputStream,%20java.io.OutputStream,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.os.FileUtils.ProgressListener)(https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/io/OutputStream out, https://developer.android.com/reference/android/os/CancellationSignal signal, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/FileUtils.ProgressListener listener) ` Copy the contents of one stream to another. |
| ` static long` | ` https://developer.android.com/reference/android/os/FileUtils#copy(java.io.FileDescriptor,%20java.io.FileDescriptor,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.os.FileUtils.ProgressListener)(https://developer.android.com/reference/java/io/FileDescriptor in, https://developer.android.com/reference/java/io/FileDescriptor out, https://developer.android.com/reference/android/os/CancellationSignal signal, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/FileUtils.ProgressListener listener) ` Copy the contents of one FD to another. |
| ` static long` | ` https://developer.android.com/reference/android/os/FileUtils#copy(java.io.FileDescriptor,%20java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor in, https://developer.android.com/reference/java/io/FileDescriptor out) ` Copy the contents of one FD to another. |
| ` static long` | ` https://developer.android.com/reference/android/os/FileUtils#copy(java.io.InputStream,%20java.io.OutputStream)(https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/io/OutputStream out) ` Copy the contents of one stream to another. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### closeQuietly

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void closeQuietly (FileDescriptor fd)
```


**This method was deprecated
in API level 30.**   

This method may suppress potentially significant exceptions, particularly when
closing writable resources. With a writable resource, a failure thrown from `close()`
should be considered as significant as a failure thrown from a write method because it may
indicate a failure to flush bytes to the underlying resource.

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

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: This value may be `null`. <br /> |

### closeQuietly

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void closeQuietly (AutoCloseable closeable)
```


**This method was deprecated
in API level 30.**   

This method may suppress potentially significant exceptions, particularly when
closing writable resources. With a writable resource, a failure thrown from `close()`
should be considered as significant as a failure thrown from a write method because it may
indicate a failure to flush bytes to the underlying resource.

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

<br />

| Parameters ||
|---|---|
| `closeable` | `AutoCloseable`: This value may be `null`. <br /> |

### copy

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: This value cannot be `null`. <br /> |
| `out` | `OutputStream`: This value cannot be `null`. <br /> |
| `signal` | `CancellationSignal`: to signal if the copy should be cancelled early. This value may be `null`. <br /> |
| `executor` | `Executor`: that listener events should be delivered via. This value may be `null`. <br /> |
| `listener` | `FileUtils.ProgressListener`: to be periodically notified as the copy progresses. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `long` | number of bytes copied. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### copy

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `in` | `FileDescriptor`: This value cannot be `null`. <br /> |
| `out` | `FileDescriptor`: This value cannot be `null`. <br /> |
| `signal` | `CancellationSignal`: to signal if the copy should be cancelled early. This value may be `null`. <br /> |
| `executor` | `Executor`: that listener events should be delivered via. This value may be `null`. <br /> |
| `listener` | `FileUtils.ProgressListener`: to be periodically notified as the copy progresses. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `long` | number of bytes copied. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### copy

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `in` | `FileDescriptor`: This value cannot be `null`. <br /> |
| `out` | `FileDescriptor`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | number of bytes copied. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### copy

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: This value cannot be `null`. <br /> |
| `out` | `OutputStream`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | number of bytes copied. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |