# FileObserver

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Constants](https://developer.android.com/reference/android/os/FileObserver#constants)\|[Ctors](https://developer.android.com/reference/android/os/FileObserver#pubctors)\|[Methods](https://developer.android.com/reference/android/os/FileObserver#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/os/FileObserver#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/os/FileObserver#inhmethods)  

# FileObserver

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/os/FileObserver "View this page in Kotlin")\|Java

`
public


abstract
class
FileObserver
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

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

<br />

*** ** * ** ***

Monitors files (using[inotify](http://en.wikipedia.org/wiki/Inotify)) to fire an event after files are accessed or changed by any process on the device (including this one). FileObserver is an abstract class; subclasses must implement the event handler[onEvent(int, java.lang.String)](https://developer.android.com/reference/android/os/FileObserver#onEvent(int,%20java.lang.String)).

Each FileObserver instance can monitor multiple files or directories. If a directory is monitored, events will be triggered for all files and subdirectories inside the monitored directory.

An event mask is used to specify which changes or actions to report. Event type constants are used to describe the possible changes in the event mask as well as what actually happened in event callbacks.

**Warning**: If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object.

<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ### Constants                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ||
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS) Event type: Data was read from a file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `int` | [ALL_EVENTS](https://developer.android.com/reference/android/os/FileObserver#ALL_EVENTS) Event mask: All valid event types, combined Value is either`0`or a combination of[ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS),[MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY),[ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB),[CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE),[CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE),[OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN),[MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM),[MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO),[CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE),[DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE),[DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF), and[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF) |
| `int` | [ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB) Event type: Metadata (permissions, owner, timestamp) was changed explicitly                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `int` | [CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE) Event type: Someone had a file or directory open read-only, and closed it                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `int` | [CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE) Event type: Someone had a file or directory open for writing, and closed it                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `int` | [CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE) Event type: A new file or subdirectory was created under the monitored directory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `int` | [DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE) Event type: A file was deleted from the monitored directory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `int` | [DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF) Event type: The monitored file or directory was deleted; monitoring effectively stops                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `int` | [MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY) Event type: Data was written to a file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `int` | [MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM) Event type: A file or subdirectory was moved from the monitored directory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `int` | [MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO) Event type: A file or subdirectory was moved to the monitored directory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `int` | [MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF) Event type: The monitored file or directory was moved; monitoring continues                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `int` | [OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN) Event type: A file or directory was opened                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

|                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File))`(`[File](https://developer.android.com/reference/java/io/File)` file) ` Equivalent to FileObserver(file, FileObserver.ALL_EVENTS).                                                                                                                                                                                                                                                      |
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File,%20int))`(`[File](https://developer.android.com/reference/java/io/File)` file, int mask) ` Create a new file observer for a certain file or directory.                                                                                                                                                                                                                                    |
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` path) ` *This constructor is deprecated. use[FileObserver(java.io.File)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File))instead.*                                                                                                                                 |
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.lang.String,%20int))`(`[String](https://developer.android.com/reference/java/lang/String)` path, int mask) ` *This constructor is deprecated. use[FileObserver(java.io.File, int)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File,%20int))instead.*                                                                                                    |
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.util.List<java.io.File>))`(`[List](https://developer.android.com/reference/java/util/List)`<`[File](https://developer.android.com/reference/java/io/File)`> files) ` Equivalent to FileObserver(paths, FileObserver.ALL_EVENTS).                                                                                                                                                                  |
| ` `[FileObserver](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.util.List<java.io.File>,%20int))`(`[List](https://developer.android.com/reference/java/util/List)`<`[File](https://developer.android.com/reference/java/io/File)`> files, int mask) ` Version of[FileObserver(java.io.File, int)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File,%20int))that allows callers to monitor multiple files or directories. |

|                                                                                                                                  ### Public methods                                                                                                                                   ||
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void` | ` `[onEvent](https://developer.android.com/reference/android/os/FileObserver#onEvent(int,%20java.lang.String))`(int event, `[String](https://developer.android.com/reference/java/lang/String)` path) ` The event handler, which must be implemented by subclasses. |
| ` void`          | ` `[startWatching](https://developer.android.com/reference/android/os/FileObserver#startWatching())`() ` Start watching for events.                                                                                                                                 |
| ` void`          | ` `[stopWatching](https://developer.android.com/reference/android/os/FileObserver#stopWatching())`() ` Stop watching for events.                                                                                                                                    |

|                                                                                                          ### Protected methods                                                                                                           ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[finalize](https://developer.android.com/reference/android/os/FileObserver#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||

## Constants

### ACCESS

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

```
public static final int ACCESS
```

Event type: Data was read from a file

<br />

Constant Value: 1 (0x00000001)  

### ALL_EVENTS

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

```
public static final int ALL_EVENTS
```

Event mask: All valid event types, combined  
Value is either`0`or a combination of[ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS),[MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY),[ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB),[CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE),[CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE),[OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN),[MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM),[MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO),[CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE),[DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE),[DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF), and[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF)

<br />

Constant Value: 4095 (0x00000fff)  

### ATTRIB

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

```
public static final int ATTRIB
```

Event type: Metadata (permissions, owner, timestamp) was changed explicitly

<br />

Constant Value: 4 (0x00000004)  

### CLOSE_NOWRITE

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

```
public static final int CLOSE_NOWRITE
```

Event type: Someone had a file or directory open read-only, and closed it

<br />

Constant Value: 16 (0x00000010)  

### CLOSE_WRITE

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

```
public static final int CLOSE_WRITE
```

Event type: Someone had a file or directory open for writing, and closed it

<br />

Constant Value: 8 (0x00000008)  

### CREATE

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

```
public static final int CREATE
```

Event type: A new file or subdirectory was created under the monitored directory

<br />

Constant Value: 256 (0x00000100)  

### DELETE

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

```
public static final int DELETE
```

Event type: A file was deleted from the monitored directory

<br />

Constant Value: 512 (0x00000200)  

### DELETE_SELF

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

```
public static final int DELETE_SELF
```

Event type: The monitored file or directory was deleted; monitoring effectively stops

<br />

Constant Value: 1024 (0x00000400)  

### MODIFY

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

```
public static final int MODIFY
```

Event type: Data was written to a file

<br />

Constant Value: 2 (0x00000002)  

### MOVED_FROM

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

```
public static final int MOVED_FROM
```

Event type: A file or subdirectory was moved from the monitored directory

<br />

Constant Value: 64 (0x00000040)  

### MOVED_TO

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

```
public static final int MOVED_TO
```

Event type: A file or subdirectory was moved to the monitored directory

<br />

Constant Value: 128 (0x00000080)  

### MOVE_SELF

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

```
public static final int MOVE_SELF
```

Event type: The monitored file or directory was moved; monitoring continues

<br />

Constant Value: 2048 (0x00000800)  

### OPEN

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

```
public static final int OPEN
```

Event type: A file or directory was opened

<br />

Constant Value: 32 (0x00000020)

## Public constructors

### FileObserver

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

```
public FileObserver (File file)
```

Equivalent to FileObserver(file, FileObserver.ALL_EVENTS).

<br />

|                     Parameters                     ||
|--------|--------------------------------------------|
| `file` | `File`: This value cannot be`null`. <br /> |

### FileObserver

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

```
public FileObserver (File file, 
                int mask)
```

Create a new file observer for a certain file or directory. Monitoring does not start on creation! You must call[startWatching()](https://developer.android.com/reference/android/os/FileObserver#startWatching())before you will receive events.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ||
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `file` | `File`: The file or directory to monitor This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `mask` | `int`: The event or events (added together) to watch for Value is either`0`or a combination of[ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS),[MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY),[ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB),[CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE),[CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE),[OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN),[MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM),[MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO),[CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE),[DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE),[DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF), and[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF) <br /> |

### FileObserver

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

```
public FileObserver (String path)
```

<br />

**This constructor is deprecated.**   
use[FileObserver(java.io.File)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File))instead.

Equivalent to FileObserver(path, FileObserver.ALL_EVENTS).

<br />

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

### FileObserver

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

```
public FileObserver (String path, 
                int mask)
```

<br />

**This constructor is deprecated.**   
use[FileObserver(java.io.File, int)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File,%20int))instead.

Create a new file observer for a certain file or directory. Monitoring does not start on creation! You must call[startWatching()](https://developer.android.com/reference/android/os/FileObserver#startWatching())before you will receive events.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ||
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `path` | `String`: The file or directory to monitor <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `mask` | `int`: The event or events (added together) to watch for Value is either`0`or a combination of[ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS),[MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY),[ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB),[CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE),[CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE),[OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN),[MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM),[MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO),[CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE),[DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE),[DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF), and[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF) <br /> |

### FileObserver

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

```
public FileObserver (List<File> files)
```

Equivalent to FileObserver(paths, FileObserver.ALL_EVENTS).

<br />

|                                       Parameters                                        ||
|---------|--------------------------------------------------------------------------------|
| `files` | `List`: The files or directories to monitor This value cannot be`null`. <br /> |

### FileObserver

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

```
public FileObserver (List<File> files, 
                int mask)
```

Version of[FileObserver(java.io.File, int)](https://developer.android.com/reference/android/os/FileObserver#FileObserver(java.io.File,%20int))that allows callers to monitor multiple files or directories.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `files` | `List`: The files or directories to monitor This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `mask`  | `int`: The event or events (added together) to watch for Value is either`0`or a combination of[ACCESS](https://developer.android.com/reference/android/os/FileObserver#ACCESS),[MODIFY](https://developer.android.com/reference/android/os/FileObserver#MODIFY),[ATTRIB](https://developer.android.com/reference/android/os/FileObserver#ATTRIB),[CLOSE_WRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_WRITE),[CLOSE_NOWRITE](https://developer.android.com/reference/android/os/FileObserver#CLOSE_NOWRITE),[OPEN](https://developer.android.com/reference/android/os/FileObserver#OPEN),[MOVED_FROM](https://developer.android.com/reference/android/os/FileObserver#MOVED_FROM),[MOVED_TO](https://developer.android.com/reference/android/os/FileObserver#MOVED_TO),[CREATE](https://developer.android.com/reference/android/os/FileObserver#CREATE),[DELETE](https://developer.android.com/reference/android/os/FileObserver#DELETE),[DELETE_SELF](https://developer.android.com/reference/android/os/FileObserver#DELETE_SELF), and[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF) <br /> |

## Public methods

### onEvent

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

```
public abstract void onEvent (int event, 
                String path)
```

The event handler, which must be implemented by subclasses.

This method is invoked on a special FileObserver thread. It runs independently of any threads, so take care to use appropriate synchronization! Consider using[Handler.post(Runnable)](https://developer.android.com/reference/android/os/Handler#post(java.lang.Runnable))to shift event handling work to the main thread to avoid concurrency problems.

Event handlers must not throw exceptions.

<br />

<br />

|                                                                                                                                     Parameters                                                                                                                                      ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | `int`: The type of event which happened <br />                                                                                                                                                                                                                             |
| `path`  | `String`: The path, relative to the main monitored file or directory, of the file or directory which triggered the event. This value can be`null`for certain events, such as[MOVE_SELF](https://developer.android.com/reference/android/os/FileObserver#MOVE_SELF). <br /> |

### startWatching

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

```
public void startWatching ()
```

Start watching for events. The monitored file or directory must exist at this time, or else no events will be reported (even if it appears later). If monitoring is already started, this call has no effect.

<br />

### stopWatching

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

```
public void stopWatching ()
```

Stop watching for events. Some events may be in process, so events may continue to be reported even after this method completes. If monitoring is already stopped, this call has no effect.

<br />

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the`finalize`method to dispose of system resources or to perform other cleanup.

The general contract of`finalize`is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The`finalize`method may take any action, including making this object available again to other threads; the usual purpose of`finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The`finalize`method of class`Object`performs no special action; it simply returns normally. Subclasses of`Object`may override this definition.

The Java programming language does not guarantee which thread will invoke the`finalize`method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the`finalize`method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The`finalize`method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the`finalize`method causes the finalization of this object to be halted, but is otherwise ignored.

<br />