Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1013732 // Test WatchService (watching directories for changes)

JavaX source code (desktop) [tags: archive use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1009L/7K).

1  
!7
2  
3  
import java.nio.file.*;
4  
import static java.nio.file.StandardWatchEventKinds.*;
5  
6  
p {
7  
  final Path path = FileSystems.getDefault().getPath(userHome());
8  
  
9  
  WatchService watchService = FileSystems.getDefault().newWatchService();
10  
  final WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW);
11  
  while licensed {
12  
    final WatchKey wk = watchService.take();
13  
    print("Key taken");
14  
    
15  
    for (WatchEvent<?> event : wk.pollEvents()) pcall {
16  
      final Path changed = (Path) event.context();
17  
      print("Changed: " + changed);
18  
    }
19  
    
20  
    bool valid = wk.reset();
21  
    if (!valid)
22  
      print("Key has been unregistered");
23  
  }
24  
}

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: 487 / 1309
Version history: 6 change(s)
Referenced in: [show references]