用于创建/删除/等的Java文件夹监视器?

发布于 2024-08-01 16:55:10 字数 85 浏览 3 评论 0原文

有没有一种方法可以监视java中的文件夹以查看它们何时更新,即文件创建、删除、重命名等。 还有什么方法可以设置它只查找以某个前缀(即 img)开头的文件?

Is there a way to monitor folders in java to see when they are updated, ie file created, deleted, renamed,etc. And also is there any way to set it that it only looks for files that begin with a certain prefix, ie img?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟织青萝梦 2024-08-08 16:55:10

在 Java 7 中,有一个 WatchService API 作为 NIO2 的一部分。 对于早期的 Java 版本,除了手动轮询之外,没有纯 Java 解决方案。

In Java 7 there is a WatchService API as part of NIO2. For earlier Java versions there's no pure Java solution except for manual polling.

浅笑依然 2024-08-08 16:55:10

您可以使用 inotify-java API,它提供了基于事件的机制,使用 glibc(2.4 版及更高版本)和 Linux 内核(从 2.6.13 开始)提供的 inotify 接口来监视 Linux 文件系统事件。
特征
简单易用,功能齐全,支持 inotify
低内存占用 API 使用阻塞调用,从而降低 CPU 使用率

You can use inotify-java API that provides an event-based mechanism for monitoring Linux file system events using the inotify interface provided by glibc (versions 2.4 and up) and the Linux kernel, starting from 2.6.13.
Features
Simple, easy to use feature-complete support for inotify
Low memory footprint API uses blocking calls yielding low CPU usage

时光与爱终年不遇 2024-08-08 16:55:10

请参阅我的回答< /a> 类似的问题。

详细的机制不会过滤文件名/类型。 您必须与建议的解决方案一起执行此操作。

See my answer to a similar question.

The mechanisms detailed won't filter on a file name/type. You'll have to do that alongside the suggested solutions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文