File watching questions
I'd like to use a file watcher to watch for a file containing a port number that will be created by a process I'm running with a run config. What's the best way to achieve this? I know the full path the port will be written to. Should I use the FileWatcher interface for this, or is the native JDK7 watcher a better fit? When using the FileWatcher, are the events received immediately when the underlying FS is updated, or only when the VFS is refreshed?
请先登录再写评论。
I'd not recommend using VFS for anything but project files.In this case, NIO is better on all counts.
VFS events are sent on refresh.
Great, thanks Roman.
I finally got around to implementing this. The problem is that the NIO2 file watching is very slow on OSX, I believe it uses polling rather than true file watching. There are a couple of native libraries out there that work around this, but I thought I'd check first - is there any way to access the native file watcher used by IntelliJ from a plugin?
Yep, it uses `PollingWatchService` on macOS (what a shame).
The only way to interface with the watcher is through VFS (`LocalFileSystem#addRootToWatch` and so on).