java - 如何监听java应用程序的文件执行事件?

标签 java

我想从 java 应用程序监听我的计算机中文件的执行情况。我需要这些文件的详细信息。如何监听文件执行事件?

最佳答案

来自documentation -

Java 7 引入了 Java WatchService

A watch service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its display of the list of files when files are created or deleted. A Watchable object is registered with a watch service by invoking its register method, returning a WatchKey to represent the registration. When an event for an object is detected the key is signalled, and if not currently signalled, it is queued to the watch service so that it can be retrieved by consumers that invoke the poll or take methods to retrieve keys and process events. Once the events have been processed the consumer invokes the key's reset method to reset the key which allows the key to be signalled and re-queued with further events.

关于java - 如何监听java应用程序的文件执行事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953150/

相关文章:

java - 按钮1.setOnClickListener(this);导致空指针

java - 需要标识符吗?

java - 合并两个不同大小的堆

java - 写入随机访问文件

java - 给定一个数字,返回从 1 开始到该数字不重复的数字的个数?

java - 在 Intellij IDE 中对 ant 输入处理 java.lang.NegativeArraySizeException

java - 什么时候 ArrayList 比 Java 中的数组更可取?

java - Swing JTable - 根据前一行的功能更改行的背景颜色

javascript - 如何通过ajax向java servlet发送数据

java - 文件IO和异常处理错误