Can the Java File method “canWrite()” support locking?

后端 未结 5 2551
遥遥无期
遥遥无期 2021-02-19 19:16

I have a Java application that monitors a folder for incoming XML files. When a new file is detected I need to test the file that it is not currently being updated and is close

5条回答
  •  日久生厌
    2021-02-19 19:37

    As far as I know, there is no way to tell if another process currently has an open handle to a file from Java. One option is to use the FileLock class from new io. This isn't supported on all platforms, but if the files are local and the process writing the file cooperates, this should work for any platform supporting locks.

提交回复
热议问题