Question

I need to lock a file in unix/linux OS. I have googled and read about java.nio.channels Filelock and Reentrant File Lock . But both works in Windows but not in unix. Is there any other way of implementing a lock on file in unix? Any sample code would be highly appreciated.

Thanks, Vignesh

No correct solution

OTHER TIPS

you could have a look at this (not java related) post - https://unix.stackexchange.com/questions/20104/is-there-any-way-to-prevent-deletion-of-certain-files-from-user-owned-directory.

it contains 2 solutions - either chowning the file by root and setting the sticky bit or using ext2/3/4 specific attributes.

both of these solutions are doable from java using System.exec()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top