How to throw an exception when a file lock fails because it's open in another program?

StackOverflow https://stackoverflow.com/questions/22760722

  •  24-06-2023
  •  | 
  •  

문제

How do I throw an exception in Java when a file lock fails because it's open in another program? If I'm trying to get a lock with

filelock = rf.lock();

Right now all it does is freeze if the file is open in another program.

도움이 되었습니까?

해결책

Check out the FileChannel#tryLock(...) function. That should do what you need.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top