FileChangeListener and listen to changes on Physical File System

View: New views
3 Messages — Rating Filter:   Alert me  

FileChangeListener and listen to changes on Physical File System

by Gonzalo Tirapegui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi !

    I'm currently working on a code that make a Memory FileSystem (with
Netbeans API FileSystem) based on a root folder given by parameter .
When i read recursively every subdirectory (or file) under the root
folder , i assign a FileChangeListener class implementation through the
following instruction :

             FileUtil.addFileChangeListener(new MyListener(), tempFile);

   i understand this function listen to the PHYSICAL files and directory
changes (renaming , deleting , adding a new File) and notify to the
implementation of FileChangeListener to execute the corresponding code ,
but it doesn't work for me  .... does anyone knows how to do it?


Regards , Gonzalo Tirapegui

Re: FileChangeListener and listen to changes on Physical File System

by Jesse Glick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gonzalo Tirapegui Medina wrote:
> FileUtil.addFileChangeListener(new MyListener(), tempFile);
>
> i understand this function listen to the PHYSICAL files and directory
> changes (renaming , deleting , adding a new File) and notify to the
> implementation of FileChangeListener to execute the corresponding code ,
> but it doesn't work for me

1. The above should work on individual files, but if you wish to use one listener to check for changes anywhere beneath a file tree, you will need
addRecursiveFileChangeListener in 6.8.

2. You will not be notified if changes on disk (using java.io.File methods, or out-of-process changes) unless there is some trigger causing NetBeans to look for them. See
#26230 for a request for native-backed polling.

Anyway I wonder what it is you're trying to accomplish. If you have a physical file tree, you can treat it as a FileObject tree just using FileUtil.toFileObject. If you
want to treat it as read-only but have memory-backed changes as an overlay, use MultiFileSystem with FileUtil.createMemoryFileSystem.


Re: FileChangeListener and listen to changes on Physical File System

by Aekold Helbrass :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 29, 2009 at 8:44 PM, Gonzalo Tirapegui Medina
<tecklastaire@...> wrote:

> Hi !
>
>   I'm currently working on a code that make a Memory FileSystem (with
> Netbeans API FileSystem) based on a root folder given by parameter . When i
> read recursively every subdirectory (or file) under the root folder , i
> assign a FileChangeListener class implementation through the following
> instruction :
>
>            FileUtil.addFileChangeListener(new MyListener(), tempFile);
>
>  i understand this function listen to the PHYSICAL files and directory
> changes (renaming , deleting , adding a new File) and notify to the
> implementation of FileChangeListener to execute the corresponding code , but
> it doesn't work for me  .... does anyone knows how to do it?

You may try this
https://jna.dev.java.net/nonav/javadoc/com/sun/jna/examples/FileMonitor.html
JNA guys are listing NetBeans in "Projects Using JNA".