[英]How can I get FileWatcher to tell me the file modified is a folder?
In Java, I am using the procedure presented here . 在Java中,我正在使用此处介绍的过程。 Everything is working fine when I am interacting with files, but I am running into problems when dealing with folders. 与文件进行交互时,一切工作正常,但是在处理文件夹时遇到了问题。 The code does indeed detect that a new folder has been added/modified etc. but it does not tell me that is a folder and not a file. 该代码确实检测到已添加/修改了新文件夹等,但是它没有告诉我这是文件夹而不是文件。
It will say "foo has been added", this means foo can be a file or folder, and when I am trying to build a link out of that information, it matters. 它会说“已经添加了foo”,这意味着foo可以是文件或文件夹,而当我尝试根据该信息构建链接时,这很重要。
What is the solution that I should adopt in this case? 在这种情况下,我应该采用什么解决方案?
You can check whether it is a file or folder by using isFile() or isDirectory() 您可以使用isFile()或isDirectory()检查它是文件还是文件夹。
String filePath = watchEvent.context().toString();
File file = new File(filePath);
//here you can identify whether it is file or folder isFile() or isDirectory()
if(file.isFile()){
//is a file
}
if(file.isDirectory()){
//is a directory
}
Hope the above may help you . 希望以上内容对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.