Note: These pages are being reviewed.
I am listening for changes in a folder/file but when there are changes I do not receive an event
If you are adding/deleting/changes using the FileSystems API - i.e. adding using FileUtil.createData() then it should work.
If not, get the parent folder as a FileObject and call theFolder.getFileSystem().refresh().
NetBeans will automatically do the refresh if focus is shifted away from the main window and back. However if files are created by an external process, or by using java.io.File.mkdir() or java.io.File.createNewFile() (which you shouldn’t be using inside a NetBeans module unless you really need to), changes will not be noticed until something forces a refresh.
The reasons for the way this is handled are twofold:
There is not native support in Java for listening for changes in a file/folder (yet), though most OS’s natively support it
We used to use a system that polled on a timer, but this is a bad idea because the user can be using, say, email, and most of the in-memory copy of NetBeans can have been swapped out to disk by the OS - but to check for modified files, it has to be dragged back into memory out of the swap file to see if some files have changed, even though the user is using another application. That hurts performance of the user’s other applications.
If you are creating files or folders programmatically, use FileObject, not java.io.File and any nodes your UI shows for those files will automatically update.
Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqListeningForFileChanges , that was last modified by NetBeans user Tboudreau on 2010-01-23T20:41:36Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.