java 监控文件夹 WatchService
原文链接 :http://blog.csdn.net/lirx_tech/article/details/51425364
public class WacthFileUtil {
public static void main(String[] args) {
//define a folder root
Path myDir = Paths.get("test\\phone");
while (true) {
try {
WatchService watcher = myDir.getFileSystem().newWatchService();
myDir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey watckKey = watcher.take();
List<WatchEvent<?>> events = watckKey.pollEvents();
for (WatchEvent event : events) {
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
System.out.println("Created: " + event.context().toString());
}
if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
System.out.println("Delete: " + event.context().toString());
}
if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
System.out.println("Modify: " + event.context().toString());
}
}
} catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}
}
}
java 监控文件夹 WatchService的更多相关文章
- java监控文件夹下的文件变化使用jnotify
https://blog.csdn.net/codepython/article/details/42341243?utm_source=blogxgwz1 使用jnotify https://blo ...
- Java实现文件夹下文件实时监控
一.commons-io方法 1.使用Commons-io的monitor下的相关类可以处理对文件进行监控,它采用的是观察者模式来实现的 (1)可以监控文件夹的创建.删除和修改 (2)可以监控文件的创 ...
- Storm监控文件夹变化 统计文件单词数量
监控指定文件夹,读取文件(新文件动态读取)里的内容,统计单词的数量. FileSpout.java,监控文件夹,读取新文件内容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- Python 的 pyinotify 模块 监控文件夹和文件的变动
官方参考: https://github.com/seb-m/pyinotify/wiki/Events-types https://github.com/seb-m/pyinotify/wiki/I ...
- 解决Eclipse建立Maven项目后无法建立src/main/java资源文件夹的办法
建立好一个Maven项目后,如果Java Resources资源文件下没有src/main/java文件夹,并且在手动创建这个文件时提示“已存在文件”. 这说明,在这个项目配置中已经有了src/m ...
- java 遍历文件夹里的文件
Java遍历文件夹的2种方法: A.不使用递归: import java.io.File; import java.util.LinkedList; public class FileSystem { ...
- JAVA 遍历文件夹下的所有文件
JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...
- Java操作文件夹的工具类
Java操作文件夹的工具类 import java.io.File; public class DeleteDirectory { /** * 删除单个文件 * @param fileName 要删除 ...
- JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...
随机推荐
- nginx学习笔记2
nginx基础配置 一.nginx常用命令 nginx -s reload:在nginx已经启动的情况下重新加载配置文件(平滑重启) nginx -s reopen:重新打开日志文件 nginx -c ...
- canal
https://github.com/alibaba/canal/wiki/QuickStart https://github.com/alibaba/canal/releases/download/ ...
- python读写符号的含义
r 打开只读文件,该文件必须存在. r+ 打开可读写的文件,该文件必须存在. w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失.若文件不存在则建立该文件. w+ 打开可读写文件,若文件 ...
- 关于i7 8700以上系列主机,安装虚拟机Win7下连接U盘,故障处理的补充说明
正如前文“虚拟机下怎么连接U盘,如何使用U盘?一策书(湘岳阳万江波)的随笔”所言,我在win10下的虚拟机win7(i7 9700),而且听说了是不支持Win7的,其原因是不支持USB的驱动问题. 我 ...
- AtomicInteger例子
AtomicInteger可以保证原子性,可见性,有序性 public class AtomicIntegerTest { private static AtomicInteger value = n ...
- [转帖]linux lsof 用法简介
linux lsof 用法简介 https://www.cnblogs.com/saneri/p/5333333.html 1.简介: lsof(list open files)是一个列出当前系统打开 ...
- 正在开发的JavaScript引擎有哪些?
正在开发的JavaScript引擎有哪些? V8,用C++编写,开放源代码,由Google丹麦开发,是Google Chrome的一部分,也用于Node.js. JavaScriptCore,开放源代 ...
- SpringBoot+Mybatis+Druid批量更新 multi-statement not allow异常
本文链接:https://blog.csdn.net/weixin_43947588/article/details/90109325 注:该文是本博主记录学习之用,没有太多详细的讲解,敬请谅解! ...
- select into 与 insert into select
1.select into select into 语句把一个表中的数据插入到另一个表中. 不需要创建临时表,在运行过程中自动创建. 基本语法: select * into #table_Name f ...
- K8S CoreDNS部署失败,发现的一个问题
K8S CoreDNS部署失败,查看错误日志,提示如下 root >> kubectl get all --all-namespaces -o wide root >> kub ...