Deepak Menon
Deepak Menon

Reputation: 1

How do i check if a file has opened streams using java

In windows,if you try to delete a file which has streams opened,it will return false. Where was in linux,if you try to delete a file which is open,it just deletes the file. Now i need a mechanism which works in both os to check if a file has streams opened(If the files is used by some other application)

Upvotes: 0

Views: 1206

Answers (2)

Rupok
Rupok

Reputation: 2082

File lock is platform-dependent. On some platforms, the file lock is advisory, which means that unless an application checks for a file lock, it will not be prevented from accessing the file. On other platforms, the file lock is mandatory, which means that a file lock prevents any application from accessing the file.

http://www.exampledepot.com/egs/java.nio/SetFileLock.html

Upvotes: 2

Suraj Chandran
Suraj Chandran

Reputation: 24791

The reason is Linux uses advisory locks. Hence applications have to collaborate using locks to communicate on files.

I am not sure if its possible with pure java alone.

Upvotes: 0

Related Questions