# DocumentFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:documentfile:28.0.0-alpha1  
Summary:[Methods](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#)  

# DocumentFile

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


abstract
class
DocumentFile
`  
`

extends Object


``


`

|---|------------------------------------------|
| java.lang.Object                            ||
| ↳ | android.support.v4.provider.DocumentFile |

<br />

*** ** * ** ***

Representation of a document backed by either a[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)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[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(Context, Uri)](https://developer.android.com/reference/android/support/v4/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(Context, Uri)](https://developer.android.com/reference/android/support/v4/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/android/support/v4/provider/DocumentFile#getUri())to obtain the Uri representing the underlying document for that object, for use with[openInputStream(Uri)](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(File)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromFile(java.io.File))which emulates the behavior of a[DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).  
**See also:**

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

## Summary

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

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### canRead

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean canRead ()
```

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

<br />

|                              Returns                               ||
|-----------|---------------------------------------------------------|
| `boolean` | `true`if this file can be read,`false`otherwise. <br /> |

### canWrite

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean canWrite ()
```

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

<br />

|                                Returns                                ||
|-----------|------------------------------------------------------------|
| `boolean` | `true`if this file can be written,`false`otherwise. <br /> |

**See also:**

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

### createDirectory

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile createDirectory (String displayName)
```

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

<br />

|                      Parameters                       ||
|---------------|----------------------------------------|
| `displayName` | `String`: name of new directory <br /> |

|                                                                                Returns                                                                                ||
|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | file representing newly created directory, or null if failed <br /> |

|                                                                                                                          Throws                                                                                                                           ||
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `UnsupportedOperationException` | when working with a single document created from[fromSingleUri(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromSingleUri(android.content.Context, android.net.Uri)). |

**See also:**

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

### createFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile createFile (String mimeType, 
                String displayName)
```

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

<br />

|                                                                      Parameters                                                                       ||
|---------------|----------------------------------------------------------------------------------------------------------------------------------------|
| `mimeType`    | `String`: MIME type of new document, such as`image/png`or`audio/flac` <br />                                                           |
| `displayName` | `String`: name of new document, without any file extension appended; the underlying provider may choose to append the extension <br /> |

|                                                                               Returns                                                                                ||
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | file representing newly created document, or null if failed <br /> |

|                                                                                                                          Throws                                                                                                                           ||
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `UnsupportedOperationException` | when working with a single document created from[fromSingleUri(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromSingleUri(android.content.Context, android.net.Uri)). |

**See also:**

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

### delete

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean delete ()
```

Deletes this file.

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

<br />

|                              Returns                               ||
|-----------|---------------------------------------------------------|
| `boolean` | `true`if this file was deleted,`false`otherwise. <br /> |

**See also:**

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

### exists

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean exists ()
```

Returns a boolean indicating whether this file can be found.

<br />

|                            Returns                            ||
|-----------|----------------------------------------------------|
| `boolean` | `true`if this file exists,`false`otherwise. <br /> |

### findFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile findFile (String displayName)
```

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

<br />

|           Parameters           ||
|---------------|-----------------|
| `displayName` | `String` <br /> |

|                                                 Returns                                                  ||
|--------------------------------------------------------------------------------------------------|--------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | <br /> |

|                                                                                                                          Throws                                                                                                                           ||
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `UnsupportedOperationException` | when working with a single document created from[fromSingleUri(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromSingleUri(android.content.Context, android.net.Uri)). |

### fromFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile fromFile (File file)
```

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

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

<br />

|      Parameters       ||
|--------|---------------|
| `file` | `File` <br /> |

|                                                 Returns                                                  ||
|--------------------------------------------------------------------------------------------------|--------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | <br /> |

### fromSingleUri

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile fromSingleUri (Context context, 
                Uri singleUri)
```

Create a[DocumentFile](https://developer.android.com/reference/android/support/v4/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.

<br />

|                                                                                                                                                                                       Parameters                                                                                                                                                                                        ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`   | `Context` <br />                                                                                                                                                                                                                                                                                                                                                           |
| `singleUri` | `Uri`: 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. <br /> |

|                                                 Returns                                                  ||
|--------------------------------------------------------------------------------------------------|--------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | <br /> |

### fromTreeUri

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile fromTreeUri (Context context, 
                Uri treeUri)
```

Create a[DocumentFile](https://developer.android.com/reference/android/support/v4/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.

<br />

|                                                                                                                                Parameters                                                                                                                                 ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | `Context` <br />                                                                                                                                                                                                                                               |
| `treeUri` | `Uri`: 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. <br /> |

|                                                 Returns                                                  ||
|--------------------------------------------------------------------------------------------------|--------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | <br /> |

### getName

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getName ()
```

Return the display name of this document.

<br />

|     Returns      ||
|----------|--------|
| `String` | <br /> |

**See also:**

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

### getParentFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile getParentFile ()
```

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

<br />

|                                                 Returns                                                  ||
|--------------------------------------------------------------------------------------------------|--------|
| [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | <br /> |

### getType

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getType ()
```

Return the MIME type of this document.

<br />

|     Returns      ||
|----------|--------|
| `String` | <br /> |

**See also:**

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

### getUri

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Uri getUri ()
```

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(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#isDocumentUri(android.content.Context, android.net.Uri))to test if the returned Uri is backed by a[DocumentsProvider](https://developer.android.com/reference/android/provider/DocumentsProvider.html).

<br />

|                                   Returns                                   ||
|---------------------------------------------------------------------|--------|
| [Uri](https://developer.android.com/reference/android/net/Uri.html) | <br /> |

**See also:**

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

### isDirectory

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isDirectory ()
```

Indicates if this file represents a*directory*.

<br />

|                                Returns                                ||
|-----------|------------------------------------------------------------|
| `boolean` | `true`if this file is a directory,`false`otherwise. <br /> |

**See also:**

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

### isDocumentUri

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isDocumentUri (Context context, 
                Uri uri)
```

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

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |
| `uri`     | `Uri` <br />     |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### isFile

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isFile ()
```

Indicates if this file represents a*file*.

<br />

|                             Returns                              ||
|-----------|-------------------------------------------------------|
| `boolean` | `true`if this file is a file,`false`otherwise. <br /> |

**See also:**

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

### isVirtual

added in[version 25.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isVirtual ()
```

Indicates if this file represents a*virtual*document.

<br />

|                           Returns                           ||
|-----------|--------------------------------------------------|
| `boolean` | `true`if this file is a virtual document. <br /> |

**See also:**

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

### lastModified

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
long lastModified ()
```

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.

<br />

|                          Returns                          ||
|--------|---------------------------------------------------|
| `long` | the time when this file was last modified. <br /> |

**See also:**

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

### length

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
long length ()
```

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.

<br />

|                     Returns                      ||
|--------|------------------------------------------|
| `long` | the number of bytes in this file. <br /> |

**See also:**

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

### listFiles

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DocumentFile[] listFiles ()
```

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

<br />

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------------|------------------------------------|
| [DocumentFile[]](https://developer.android.com/reference/android/support/v4/provider/DocumentFile) | an array of files or`null`. <br /> |

|                                                                                                                          Throws                                                                                                                           ||
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `UnsupportedOperationException` | when working with a single document created from[fromSingleUri(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromSingleUri(android.content.Context, android.net.Uri)). |

**See also:**

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

### renameTo

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean renameTo (String displayName)
```

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/android/support/v4/provider/DocumentFile#getUri())and[getType()](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#getType())may change to reflect the rename.

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

<br />

|                      Parameters                       ||
|---------------|----------------------------------------|
| `displayName` | `String`: the new display name. <br /> |

|              Returns               ||
|-----------|-------------------------|
| `boolean` | true on success. <br /> |

|                                                                                                                          Throws                                                                                                                           ||
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `UnsupportedOperationException` | when working with a single document created from[fromSingleUri(Context, Uri)](https://developer.android.com/reference/android/support/v4/provider/DocumentFile#fromSingleUri(android.content.Context, android.net.Uri)). |

**See also:**

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

  ## Classes

  - [DocumentFile](https://developer.android.com/reference/android/support/v4/provider/DocumentFile)
  - [FontRequest](https://developer.android.com/reference/android/support/v4/provider/FontRequest)
  - [FontsContractCompat](https://developer.android.com/reference/android/support/v4/provider/FontsContractCompat)
  - [FontsContractCompat.Columns](https://developer.android.com/reference/android/support/v4/provider/FontsContractCompat.Columns)
  - [FontsContractCompat.FontFamilyResult](https://developer.android.com/reference/android/support/v4/provider/FontsContractCompat.FontFamilyResult)
  - [FontsContractCompat.FontInfo](https://developer.android.com/reference/android/support/v4/provider/FontsContractCompat.FontInfo)
  - [FontsContractCompat.FontRequestCallback](https://developer.android.com/reference/android/support/v4/provider/FontsContractCompat.FontRequestCallback)