java - 监视服务两次更新单个文件
问题描述
我第一次使用手表服务,我正在尝试使用手表服务更新文件,但它会两次更新该文件。
boolean valid = true;
do{
WatchKey watchKey = watchService.take();
for(WatchEvent<?> event : watchKey.pollEvents()){
WatchEvent.Kind kind = event.kind();
if(StandardWatchEventKinds.ENTRY_CREATE.equals(kind)){
String fileName = event.context().toString();
}
if(StandardWatchEventKinds.ENTRY_MODIFY.equals(kind)){
String fileName = event.context().toString();
}
if(StandardWatchEventKinds.ENTRY_DELETE.equals(kind)){
String fileName = event.context().toString();
}
}
valid = watchKey.reset();
}while(valid);
有时,当我想在删除第一个文件后再次创建相同的文件时,我也会遇到另一个错误。然后我得到以下错误
java.io.FileNotFoundException: D:\Watson\docs\FMO-OMS_Requirements.docx (The process cannot access the file because it is being used by another process)
解决方案
推荐阅读
- kotlin - android中的Tablayout错误无法正确显示tabitem中图标的默认颜色
- python - Django 中的套接字
- javascript - 基于星期几引导的导航选项卡
- javascript - 在 JavaScript 中从 Firebase 中删除特定节点
- r - 如何为均值 CVaR 投资组合优化设置固定收益?
- python - 将周特征值更改为日期时间格式
- android - Jetpack 撰写状态没有得到观察
- python - 基于python中ID的两个日期之间的动态行数
- r - 如何使用 r RColorBrewer 自定义颜色更改饼图分段颜色
- php - 为什么我在打开我的 wordpress 网站时收到此消息(如何解决)?