# DocumentFile

# DocumentFile

Artifact:[androidx.documentfile:documentfile](https://developer.android.com/jetpack/androidx/releases/documentfile)  
[View Source](https://cs.android.com/search?q=file:androidx/documentfile/provider/DocumentFile.java+class:androidx.documentfile.provider.DocumentFile)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/documentfile/provider/DocumentFile "View this page in Java")

<br />

```
abstract class DocumentFile
```

<br />

*** ** * ** ***

Representation of a document backed by either a[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html)or a raw file on disk. This is a utility class designed to emulate the traditional[File](https://developer.android.com/reference/java/io/File.html)interface. It offers a simplified view of a tree of documents, but it has substantial overhead. For optimal performance and a richer feature set, use the[android.provider.DocumentsContract](https://developer.android.com/reference/android/provider/DocumentsContract.html)methods and constants directly.

There are several differences between documents and traditional files:

- Documents express their display name and MIME type as separate fields, instead of relying on file extensions. Some documents providers may still choose to append extensions to their display names, but that's an implementation detail.
- A single document may appear as the child of multiple directories, so it doesn't inherently know who its parent is. That is, documents don't have a strong notion of path. You can easily traverse a tree of documents from parent to child, but not from child to parent.
- Each document has a unique identifier within that provider. This identifier is an*opaque*implementation detail of the provider, and as such it must not be parsed.

Before using this class, first consider if you really need access to an entire subtree of documents. The principle of least privilege dictates that you should only ask for access to documents you really need. If you only need the user to pick a single file, use[ACTION_OPEN_DOCUMENT](https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT())or[ACTION_GET_CONTENT](https://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT()). If you want to let the user pick multiple files, add[EXTRA_ALLOW_MULTIPLE](https://developer.android.com/reference/android/content/Intent.html#EXTRA_ALLOW_MULTIPLE()). If you only need the user to save a single file, use[ACTION_CREATE_DOCUMENT](https://developer.android.com/reference/android/content/Intent.html#ACTION_CREATE_DOCUMENT()). If you use these APIs, you can pass the resulting[getData](https://developer.android.com/reference/android/content/Intent.html#getData())into[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri))to work with that document.

If you really do need full access to an entire subtree of documents, start by launching[ACTION_OPEN_DOCUMENT_TREE](https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT_TREE())to let the user pick a directory. Then pass the resulting[getData](https://developer.android.com/reference/android/content/Intent.html#getData())into[fromTreeUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromTreeUri(android.content.Context,android.net.Uri))to start working with the user selected tree.

As you navigate the tree of DocumentFile instances, you can always use[getUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getUri())to obtain the Uri representing the underlying document for that object, for use with[openInputStream](https://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri)), etc.

To simplify your code on devices running[KITKAT](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT())or earlier, you can use[fromFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromFile(java.io.File))which emulates the behavior of a[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).  

|                                               See also                                               |
|------------------------------------------------------------------------------------------------------|---|
| [DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html) |   |
| [DocumentsContract](https://developer.android.com/reference/android/provider/DocumentsContract.html) |   |

## Summary

|                                                                                            ### Public functions                                                                                             |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [canRead](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#canRead())`()` Indicates whether the current context is allowed to read from this file.                                                                                                                                                                                                                                                                                                                                                                                           |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [canWrite](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#canWrite())`()` Indicates whether the current context is allowed to write to this file.                                                                                                                                                                                                                                                                                                                                                                                          |
| `abstract `[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                    | [createDirectory](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#createDirectory(java.lang.String))`(displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Create a new directory as a direct child of this directory.                                                                                                                                                                                                                                                                        |
| `abstract `[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                    | [createFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#createFile(java.lang.String,java.lang.String))`(mimeType: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Create a new document as a direct child of this directory.                                                                                                                                                                   |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [delete](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#delete())`()` Deletes this file.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [exists](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#exists())`()` Returns a boolean indicating whether this file can be found.                                                                                                                                                                                                                                                                                                                                                                                                         |
| [DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                               | [findFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#findFile(java.lang.String))`(displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Search through[listFiles](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#listFiles())for the first document matching the given display name.                                                                                                                                                         |
| `java-static `[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)                                                                                    | [fromFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromFile(java.io.File))`(file: `[File](https://developer.android.com/reference/java/io/File.html)`)` Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the filesystem tree rooted at the given[File](https://developer.android.com/reference/java/io/File.html).                                                                                                                                    |
| `java-static `[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                 | [fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, singleUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`)` Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the single document at the given[Uri](https://developer.android.com/reference/android/net/Uri.html). |
| `java-static `[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                 | [fromTreeUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromTreeUri(android.content.Context,android.net.Uri))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, treeUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`)` Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the document tree rooted at the given[Uri](https://developer.android.com/reference/android/net/Uri.html).  |
| `abstract `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                                                             | [getName](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getName())`()` Return the display name of this document.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?`                                                                                               | [getParentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getParentFile())`()` Return the parent file of this document.                                                                                                                                                                                                                                                                                                                                                                                                               |
| `abstract `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                                                             | [getType](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getType())`()` Return the MIME type of this document.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `abstract `[Uri](https://developer.android.com/reference/android/net/Uri.html)                                                                                                                              | [getUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getUri())`()` Return a Uri for the underlying document represented by this file.                                                                                                                                                                                                                                                                                                                                                                                                   |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [isDirectory](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#isDirectory())`()` Indicates if this file represents a*directory*.                                                                                                                                                                                                                                                                                                                                                                                                            |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                           | [isDocumentUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#isDocumentUri(android.content.Context,android.net.Uri))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, uri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`?)` Test if given Uri is backed by a[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).                                                                                   |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [isFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#isFile())`()` Indicates if this file represents a*file*.                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [isVirtual](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#isVirtual())`()` Indicates if this file represents a*virtual*document.                                                                                                                                                                                                                                                                                                                                                                                                          |
| `abstract `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                    | [lastModified](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#lastModified())`()` Returns the time when this file was last modified, measured in milliseconds since January 1st, 1970, midnight.                                                                                                                                                                                                                                                                                                                                           |
| `abstract `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                    | [length](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#length())`()` Returns the length of this file in bytes.                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `abstract `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`!>` | [listFiles](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#listFiles())`()` Returns an array of files contained in the directory represented by this file.                                                                                                                                                                                                                                                                                                                                                                                 |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | [renameTo](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#renameTo(java.lang.String))`(displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Renames this file to`displayName`.                                                                                                                                                                                                                                                                                                               |

## Public functions

### canRead

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun canRead(): Boolean
```

Indicates whether the current context is allowed to read from this file.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file can be read,`false`otherwise. |

### canWrite

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun canWrite(): Boolean
```

Indicates whether the current context is allowed to write to this file.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-----------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file can be written,`false`otherwise. |

|                                                                    See also                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_FLAGS](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_FLAGS())                         |   |
| [FLAG_SUPPORTS_DELETE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_SUPPORTS_DELETE())         |   |
| [FLAG_SUPPORTS_WRITE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_SUPPORTS_WRITE())           |   |
| [FLAG_DIR_SUPPORTS_CREATE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_DIR_SUPPORTS_CREATE()) |   |

### createDirectory

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun createDirectory(displayName: String): DocumentFile?
```

Create a new directory as a direct child of this directory.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|-----------------------|
| `displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | name of new directory |

|                                                    Returns                                                    |
|---------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?` | file representing newly created directory, or null if failed |

|                                                             Throws                                                              |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException.html) | when working with a single document created from[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri)). |

|                                                                                                See also                                                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [createDocument](https://developer.android.com/reference/android/provider/DocumentsContract.html#createDocument(android.content.ContentResolver, android.net.Uri, java.lang.String, java.lang.String)) |   |

### createFile

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun createFile(mimeType: String, displayName: String): DocumentFile?
```

Create a new document as a direct child of this directory.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| `mimeType: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)    | MIME type of new document, such as`image/png`or`audio/flac`                                                           |
| `displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | name of new document, without any file extension appended; the underlying provider may choose to append the extension |

|                                                    Returns                                                    |
|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`?` | file representing newly created document, or null if failed |

|                                                             Throws                                                              |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException.html) | when working with a single document created from[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri)). |

|                                                                                                See also                                                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [createDocument](https://developer.android.com/reference/android/provider/DocumentsContract.html#createDocument(android.content.ContentResolver, android.net.Uri, java.lang.String, java.lang.String)) |   |

### delete

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun delete(): Boolean
```

Deletes this file.

Note that this method does*not* throw`IOException`on failure. Callers must check the return value.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file was deleted,`false`otherwise. |

|                                                                              See also                                                                              |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [deleteDocument](https://developer.android.com/reference/android/provider/DocumentsContract.html#deleteDocument(android.content.ContentResolver, android.net.Uri)) |   |

### exists

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun exists(): Boolean
```

Returns a boolean indicating whether this file can be found.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file exists,`false`otherwise. |

### findFile

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
fun findFile(displayName: String): DocumentFile?
```

Search through[listFiles](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#listFiles())for the first document matching the given display name. Returns`null`when no matching document is found.  

|                                                             Throws                                                              |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException.html) | when working with a single document created from[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri)). |

### fromFile

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
java-static fun fromFile(file: File): DocumentFile
```

Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the filesystem tree rooted at the given[File](https://developer.android.com/reference/java/io/File.html). This doesn't give you any additional access to the underlying files beyond what your app already has.

[getUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getUri())will return`file://`Uris for files explored through this tree.  

### fromSingleUri

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
java-static fun fromSingleUri(context: Context, singleUri: Uri): DocumentFile?
```

Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the single document at the given[Uri](https://developer.android.com/reference/android/net/Uri.html). This is only useful on devices running[KITKAT](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT())or later, and will return`null`when called on earlier platform versions.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | [Context](https://developer.android.com/reference/android/content/Context.html)used to resolve resources                                                                                                                                                                                                                                                       |
| `singleUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)           | the[getData](https://developer.android.com/reference/android/content/Intent.html#getData())from a successful[ACTION_OPEN_DOCUMENT](https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT())or[ACTION_CREATE_DOCUMENT](https://developer.android.com/reference/android/content/Intent.html#ACTION_CREATE_DOCUMENT())request. |

### fromTreeUri

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
java-static fun fromTreeUri(context: Context, treeUri: Uri): DocumentFile?
```

Create a[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)representing the document tree rooted at the given[Uri](https://developer.android.com/reference/android/net/Uri.html). This is only useful on devices running[LOLLIPOP](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP())or later, and will return`null`when called on earlier platform versions.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | [Context](https://developer.android.com/reference/android/content/Context.html)used to resolve resources                                                                                                                                         |
| `treeUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)             | the[getData](https://developer.android.com/reference/android/content/Intent.html#getData())from a successful[ACTION_OPEN_DOCUMENT_TREE](https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT_TREE())request. |

### getName

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun getName(): String?
```

Return the display name of this document.  

|                                                               See also                                                                |
|---------------------------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_DISPLAY_NAME](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DISPLAY_NAME()) |   |

### getParentFile

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
fun getParentFile(): DocumentFile?
```

Return the parent file of this document. Only defined inside of the user-selected tree; you can never escape above the top of the tree.

The underlying[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html)only defines a forward mapping from parent to child, so the reverse mapping of child to parent offered here is purely a convenience method, and it may be incorrect if the underlying tree structure changes.  

### getType

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun getType(): String?
```

Return the MIME type of this document.  

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_MIME_TYPE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_MIME_TYPE()) |   |

### getUri

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun getUri(): Uri
```

Return a Uri for the underlying document represented by this file. This can be used with other platform APIs to manipulate or share the underlying content. You can use[isDocumentUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#isDocumentUri(android.content.Context,android.net.Uri))to test if the returned Uri is backed by a[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).  

|                                                                         See also                                                                         |
|----------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setData](https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri))                                                  |   |
| [setClipData](https://developer.android.com/reference/android/content/Intent.html#setClipData(android.content.ClipData))                                 |   |
| [openInputStream](https://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri))                         |   |
| [openOutputStream](https://developer.android.com/reference/android/content/ContentResolver.html#openOutputStream(android.net.Uri))                       |   |
| [openFileDescriptor](https://developer.android.com/reference/android/content/ContentResolver.html#openFileDescriptor(android.net.Uri, java.lang.String)) |   |

### isDirectory

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun isDirectory(): Boolean
```

Indicates if this file represents a*directory*.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-----------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file is a directory,`false`otherwise. |

|                                                         See also                                                          |
|---------------------------------------------------------------------------------------------------------------------------|---|
| [MIME_TYPE_DIR](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#MIME_TYPE_DIR()) |   |

### isDocumentUri

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
java-static fun isDocumentUri(context: Context, uri: Uri?): Boolean
```

Test if given Uri is backed by a[android.provider.DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).  

### isFile

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun isFile(): Boolean
```

Indicates if this file represents a*file*.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file is a file,`false`otherwise. |

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_MIME_TYPE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_MIME_TYPE()) |   |

### isVirtual

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun isVirtual(): Boolean
```

Indicates if this file represents a*virtual*document.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this file is a virtual document. |

|                                                                 See also                                                                  |
|-------------------------------------------------------------------------------------------------------------------------------------------|---|
| [FLAG_VIRTUAL_DOCUMENT](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_VIRTUAL_DOCUMENT()) |   |

### lastModified

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun lastModified(): Long
```

Returns the time when this file was last modified, measured in milliseconds since January 1st, 1970, midnight. Returns 0 if the file does not exist, or if the modified time is unknown.  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|--------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | the time when this file was last modified. |

|                                                                See also                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_LAST_MODIFIED](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_LAST_MODIFIED()) |   |

### length

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun length(): Long
```

Returns the length of this file in bytes. Returns 0 if the file does not exist, or if the length is unknown. The result for a directory is not defined.  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | the number of bytes in this file. |

|                                                       See also                                                        |
|-----------------------------------------------------------------------------------------------------------------------|---|
| [COLUMN_SIZE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_SIZE()) |   |

### listFiles

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun listFiles(): Array<DocumentFile!>
```

Returns an array of files contained in the directory represented by this file.  

|                                                                                             Returns                                                                                              |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[DocumentFile](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile)`!>` | an array of files. |

|                                                             Throws                                                              |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException.html) | when working with a single document created from[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri)). |

|                                                                                       See also                                                                                        |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [buildChildDocumentsUriUsingTree](https://developer.android.com/reference/android/provider/DocumentsContract.html#buildChildDocumentsUriUsingTree(android.net.Uri, java.lang.String)) |   |

### renameTo

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/documentfile#1.0.0)  

```
abstract fun renameTo(displayName: String): Boolean
```

Renames this file to`displayName`.

Note that this method does*not* throw`IOException`on failure. Callers must check the return value.

Some providers may need to create a new document to reflect the rename, potentially with a different MIME type, so[getUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getUri())and[getType](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#getType())may change to reflect the rename.

When renaming a directory, children previously enumerated through[listFiles](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#listFiles())may no longer be valid.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|-----------------------|
| `displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the new display name. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true on success. |

|                                                             Throws                                                              |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException.html) | when working with a single document created from[fromSingleUri](https://developer.android.com/reference/kotlin/androidx/documentfile/provider/DocumentFile#fromSingleUri(android.content.Context,android.net.Uri)). |

|                                                                                       See also                                                                                       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [renameDocument](https://developer.android.com/reference/android/provider/DocumentsContract.html#renameDocument(android.content.ContentResolver, android.net.Uri, java.lang.String)) |   |