Download Jar. Libraryless. Click here for Pure Java version (1009L/7K).
!7 import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; p { final Path path = FileSystems.getDefault().getPath(userHome()); WatchService watchService = FileSystems.getDefault().newWatchService(); final WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW); while licensed { final WatchKey wk = watchService.take(); print("Key taken"); for (WatchEvent<?> event : wk.pollEvents()) pcall { final Path changed = (Path) event.context(); print("Changed: " + changed); } bool valid = wk.reset(); if (!valid) print("Key has been unregistered"); } }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz
No comments. add comment
| Snippet ID: | #1013732 |
| Snippet name: | Test WatchService (watching directories for changes) |
| Eternal ID of this version: | #1013732/7 |
| Text MD5: | 1aa9e78ab0072d56ef43f100d480d273 |
| Transpilation MD5: | 52e55b3ea421132535027a4ea95fd6da |
| Author: | stefan |
| Category: | javax / io |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | Yes |
| Created/modified: | 2018-05-30 21:28:47 |
| Source code size: | 702 bytes / 24 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 742 / 1844 |
| Version history: | 6 change(s) |
| Referenced in: | [show references] |