Download Jar. Libraryless. Click here for Pure Java version (7104L/48K).
| 1 | !7 | 
| 2 | |
| 3 | import java.nio.channels.*; | 
| 4 | import java.nio.file.*; | 
| 5 | |
| 6 | static volatile S status; | 
| 7 | |
| 8 | p {
 | 
| 9 | File path = dummyFileForLockTest(); | 
| 10 | FileChannel channel = FileChannel.open(toPath(path), StandardOpenOption.CREATE, StandardOpenOption.WRITE); | 
| 11 | temp FileLock lock = channel.tryLock(); | 
| 12 | if (lock == null) print(status = "Couldn't lock."); | 
| 13 | else print(status = "Locked!"); | 
| 14 |   bot("Lock a file.");
 | 
| 15 | } | 
| 16 | |
| 17 | answer {
 | 
| 18 | if "status" ret status; | 
| 19 | } | 
Began life as a copy of #1016917
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1027063 | 
| Snippet name: | Lock a file (for testing if file locking works) | 
| Eternal ID of this version: | #1027063/1 | 
| Text MD5: | 84ecdf7716210554b46b9d2d962a8178 | 
| Transpilation MD5: | 584a28eb048ad9f9f056947d569acf18 | 
| Author: | stefan | 
| Category: | javax / io | 
| Type: | JavaX source code (desktop) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2020-02-16 16:34:58 | 
| Source code size: | 445 bytes / 19 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 546 / 1290 | 
| Referenced in: | [show references] |