DevFaqListenForChangesInNonExistentFile

(Difference between revisions)
(Created page with '__NOTOC__ ===I want to listen for changes in a file that may not exist or may be deleted and re-created=== There are some cases where you want to listen for changes in a file or…')
(I want to listen for changes in a file that may not exist or may be deleted and re-created)
 
Line 4: Line 4:
There are some cases where you want to listen for changes in a file or folder that does not exist, or may be created and deleted on the fly.
There are some cases where you want to listen for changes in a file or folder that does not exist, or may be created and deleted on the fly.
-
As of NetBeans 6.7, you can use [http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/FileUtil.html#addFileChangeListener(org.openide.filesystems.FileChangeListener,%20java.io.File) FileUtil.addFileChangeListener(FileChangeListener, File)] to listen for such changes.
+
As of NetBeans 6.7, you can use [http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/FileUtil.html#addFileChangeListener(org.openide.filesystems.FileChangeListener,%20java.io.File) FileUtil.addFileChangeListener(FileChangeListener, File)] to listen for such changes. There is also FileUtil.addRecursiveListener
-
 
+
-
Note that this is ''much'' preferable to
+
-
someFileObject.getFileSystem().addFileChangeListener(fileChangeListener);
+
-
which will notify you of ''every'' change in every file on the user's disk that the IDE finds out about, as that will trigger notifications every time the user saves, compiles, or anything - that has much more overhead, since the listener will be called very frequently and most changes will be uninteresting.
+
-
 
+
-
Note the caveats about files created outside NetBeans process or using java.io.File, as described in [[DevFaqListeningForFileChanges]], apply.
+

Current revision as of 20:01, 24 July 2010

I want to listen for changes in a file that may not exist or may be deleted and re-created

There are some cases where you want to listen for changes in a file or folder that does not exist, or may be created and deleted on the fly.

As of NetBeans 6.7, you can use FileUtil.addFileChangeListener(FileChangeListener, File) to listen for such changes. There is also FileUtil.addRecursiveListener

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo