Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#pubctors) \| [Methods](https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#inhmethods)

# AppDataFileSource

*** ** * ** ***


`
public

final

class
AppDataFileSource
`


`


`

`

extends https://developer.android.com/reference/android/os/storage/operations/sources/OperationSource


`

`


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.os.storage.operations.sources.OperationSource](https://developer.android.com/reference/android/os/storage/operations/sources/OperationSource) ||
|   | ↳ | android.os.storage.operations.sources.AppDataFileSource |

<br />

*** ** * ** ***

A source representing a file within the calling application's private app data directory.

This source is restricted to files located inside the application's internal data directory
(as returned by `https://developer.android.com/reference/android/content/Context#getDataDir()`).

### Operation Rejection

To ensure system security and integrity, operations using an `AppDataFileSource` will be
**rejected** with `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult#ERROR_UNSUPPORTED_SOURCE` or `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult#ERROR_INVALID_REQUEST` if:

- The provided path is **not absolute**.
- The path contains **path traversal elements** (e.g., "..") or redundant segments.
- The path contains **unsafe control characters** (e.g., null, newline).
- The file is **outside** the application's internal data directory (CE or DE storage). Locations such as external storage or system directories are strictly prohibited.

**Example Usage:**

    // Obtain the application's data directory using Context
    Context context = getApplicationContext();
    File myDataFile = new File(context.getDataDir(), "subfolder/my_data.txt");

    // Construct the AppDataFileSource with the File object
    AppDataFileSource source = new AppDataFileSource(myDataFile);

    // The source can now be used in storage operations

<br />

**See also:**

- `https://developer.android.com/reference/android/content/Context#getDataDir()`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#AppDataFileSource(java.io.File)(https://developer.android.com/reference/java/io/File file) ` Creates a new source for the specified file. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/io/File` | ` https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#getFile()() ` Returns the file associated with this source. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/os/storage/operations/sources/AppDataFileSource#toString()() ` Returns a string representation of this source for debugging. |

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

## Public constructors

### AppDataFileSource

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

```
public AppDataFileSource (File file)
```

Creates a new source for the specified file.

<br />

| Parameters ||
|---|---|
| `file` | `File`: The file to be used as a source. Must be within the application's data directory. This value cannot be `null`. <br /> |

## Public methods

### getFile

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

```
public File getFile ()
```

Returns the file associated with this source.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/File` | This value cannot be `null`. <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of this source for debugging.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | A string containing the source type and path. This value cannot be `null`. <br /> |