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

后端 未结 5 2567
遥遥无期
遥遥无期 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:34

    One thing that appears to work in Windows is this - Create a File() object that represents the file in question (using constructor with full filename) - Create a second identical File Object, same way. - Try firstFile.renameTo(secondFile)

    This dummy renaming exercise seems to succeed with files that are not open for editing by another app (I tested with Word), but fails if they are open.

    And as the nw filename = the old filename it doesn't create any other work.

提交回复
热议问题