WatchEvent
public
interface
WatchEvent
java.nio.file.WatchEvent<T>
|
An event or a repeated event for an object that is registered with a WatchService
.
An event is classified by its kind
and has a count
to indicate the number of times that the event has been
observed. This allows for efficient representation of repeated events. The
context
method returns any context associated with
the event. In the case of a repeated event then the context is the same for
all events.
Watch events are immutable and safe for use by multiple concurrent
threads.
Summary
Nested classes |
interface |
WatchEvent.Kind<T>
An event kind, for the purposes of identification.
|
interface |
WatchEvent.Modifier
An event modifier that qualifies how a Watchable is registered
with a WatchService .
|
Public methods |
abstract
T
|
context()
Returns the context for the event.
|
abstract
int
|
count()
Returns the event count.
|
abstract
Kind<T>
|
kind()
Returns the event kind.
|
Public methods
context
public abstract T context ()
Returns the context for the event.
In the case of ENTRY_CREATE
,
ENTRY_DELETE
, and ENTRY_MODIFY
events the context is
a Path
that is the relative
path between
the directory registered with the watch service, and the entry that is
created, deleted, or modified.
Returns |
T |
the event context; may be null |
count
public abstract int count ()
Returns the event count. If the event count is greater than 1
then this is a repeated event.
Returns |
int |
the event count |
kind
public abstract Kind<T> kind ()
Returns the event kind.
Returns |
Kind<T> |
the event kind |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# WatchEvent\n\nAdded in [API level 26](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nWatchEvent\n==========\n\n\n`\npublic\n\n\ninterface\nWatchEvent\n`\n\n\n`\n\n\n`\n\n|-------------------------------|\n| java.nio.file.WatchEvent\\\u003cT\\\u003e |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nAn event or a repeated event for an object that is registered with a [WatchService](/reference/java/nio/file/WatchService).\n\nAn event is classified by its [kind](/reference/java/nio/file/WatchEvent#kind()) and has a [count](/reference/java/nio/file/WatchEvent#count()) to indicate the number of times that the event has been\nobserved. This allows for efficient representation of repeated events. The\n[context](/reference/java/nio/file/WatchEvent#context()) method returns any context associated with\nthe event. In the case of a repeated event then the context is the same for\nall events.\n\nWatch events are immutable and safe for use by multiple concurrent\nthreads.\n\nSummary\n-------\n\n| ### Nested classes ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` interface` | [WatchEvent.Kind](/reference/java/nio/file/WatchEvent.Kind)`\u003cT\u003e` An event kind, for the purposes of identification. |\n| ` interface` | [WatchEvent.Modifier](/reference/java/nio/file/WatchEvent.Modifier) An event modifier that qualifies how a [Watchable](/reference/java/nio/file/Watchable) is registered with a [WatchService](/reference/java/nio/file/WatchService). |\n\n| ### Public methods ||\n|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|\n| ` abstract T` | ` `[context](/reference/java/nio/file/WatchEvent#context())`() ` Returns the context for the event. |\n| ` abstract int` | ` `[count](/reference/java/nio/file/WatchEvent#count())`() ` Returns the event count. |\n| ` abstract `[Kind](/reference/java/nio/file/WatchEvent.Kind)`\u003cT\u003e` | ` `[kind](/reference/java/nio/file/WatchEvent#kind())`() ` Returns the event kind. |\n\nPublic methods\n--------------\n\n### context\n\nAdded in [API level 26](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract T context ()\n```\n\nReturns the context for the event.\n\nIn the case of [ENTRY_CREATE](/reference/java/nio/file/StandardWatchEventKinds#ENTRY_CREATE),\n[ENTRY_DELETE](/reference/java/nio/file/StandardWatchEventKinds#ENTRY_DELETE), and [ENTRY_MODIFY](/reference/java/nio/file/StandardWatchEventKinds#ENTRY_MODIFY) events the context is\na `Path` that is the [relative](/reference/java/nio/file/Path#relativize(java.nio.file.Path)) path between\nthe directory registered with the watch service, and the entry that is\ncreated, deleted, or modified.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----|-----------------------------------------|\n| `T` | the event context; may be `null` \u003cbr /\u003e |\n\n### count\n\nAdded in [API level 26](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract int count ()\n```\n\nReturns the event count. If the event count is greater than `1`\nthen this is a repeated event.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------|------------------------|\n| `int` | the event count \u003cbr /\u003e |\n\n### kind\n\nAdded in [API level 26](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract Kind\u003cT\u003e kind ()\n```\n\nReturns the event kind.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------------------------------------------------------|-----------------------|\n| [Kind](/reference/java/nio/file/WatchEvent.Kind)`\u003cT\u003e` | the event kind \u003cbr /\u003e |"]]