Java: File Renaming Detection

旧街凉风 提交于 2019-11-27 15:39:41

Take a look at jpathwatch. In addition to the standard watch event kinds specified in Java 7 (ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) it also has additional events called ENTRY_RENAME_FROM and ENTRY_RENAME_TO which will fire when a file is renamed. Note that this depends on whether the underlying operating system supports file renaming events or not.

Detecting renaming of files can not be done portably. Because, surprising as it may seem, the idea that a file HAS-A name is not portable. Most Unix file systems allow a file to have any number of ASSOCIATED names (including zero names). In the Unix (POSIX) world, renaming means adding a new name and then removing the original name.

I think the jnotify would be useful in your case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!