Frage

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.

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top