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

19
LINES

< > BotCompany Repo | #1027063 // Lock a file (for testing if file locking works)

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

Download Jar. Libraryless. Click here for Pure Java version (7104L/48K).

!7

import java.nio.channels.*;
import java.nio.file.*;

static volatile S status;

p {
  File path = dummyFileForLockTest();
  FileChannel channel = FileChannel.open(toPath(path), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
  temp FileLock lock = channel.tryLock();
  if (lock == null) print(status = "Couldn't lock.");
  else print(status = "Locked!");
  bot("Lock a file.");
}

answer {
  if "status" ret status;
}

Author comment

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: 290 / 819
Referenced in: