[英]Want to define state-sequence of processes in the property file in Java
I am planning to build a program which keeps on looking the directory, and if any new file comes then it'll notify me. 我计划构建一个继续查找目录的程序,如果有新文件出现,它将通知我。 But I don't want to use Watch Service API.
但是我不想使用Watch Service API。 Is there any other simple logic to do the same?
还有其他简单的逻辑可以做到吗? without using any third party API or library?
不使用任何第三方API或库?
The Watch Service API is the simplest and most efficient way to do this, which is why it exists. Watch Service API是执行此操作的最简单,最有效的方法,这就是它存在的原因。
You can however, poll the directory and look for changes. 但是,您可以轮询目录并查找更改。 This has some down sides.
这有一些缺点。
Is there any other simple logic to do the same?
还有其他简单的逻辑可以做到吗?
Repeatedly call 反复打电话
File dir = new File(directoryName);
// note: creates a lot of garbage even if nothing changed.
File[] files = dir.listFiles();
if (files != null) {
// check for changes.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.