gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:42:43 29 4
gpt4 key购买 nike

我想从 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com