1

I have this example to listening events from fileSystem (http://java.dzone.com/news/how-watch-file-system-changes) but the events are only create, delete or modify.

I want to listen a simple double click event from my fileSystem.

Does anyone know how to do it? I can't do it by swing.

Thanks!

Felipe Gutierrez
  • 525
  • 1
  • 9
  • 20

2 Answers2

0

Java, out of the box, is not capable of watching for "a simple double click event from my fileSystem". The link you mention is about java code that can watch for other types of events, such as create, delete and modify within the file system, but double clicks are "user interface" events, which are not covered by java code as such.

However, you have rightly mentioned Swing. If you wrote a programme, using Swing, that was specifically designed to make changes to the file system, then yes, your programme could be written to listen for clicks on a button on a swing layout, and your code could then decide what to do with that click event.

mwarren
  • 2,409
  • 1
  • 22
  • 28
  • but I don't have a swing layout. I need to listen the fileSystem directory of the Operational System. – Felipe Gutierrez Apr 22 '14 at 19:57
  • Ok, so you're not using Swing. That's ok. – mwarren Jun 21 '14 at 08:13
  • Ok, so you're not using Swing. That's ok. But where does the double click come from? You have a user interface of some kind. Is it a web page with a button on it? You have to intercept the click then tell Java what to do with it. – mwarren Jun 21 '14 at 08:21
0

There is no such thing as a "double click event" in terms of the subject you're talking about.

The WatchService in Java is an interface with the implementation being platform specific (including being completely optional, depending on the platform).

The way the default implementation works on some platforms (specifically, windows / *nix) is by periodically polling the filesystem metadata for the directory you specified. If the default implementation is not monitoring access time (atime) or it's not available on the platform (or is turned off), then ... no, you can't get events for file access.

Testing this on OSX, it does not. I would have to test it on Windows and *nix to see what the results were there. I don't know that any of the default implementations do as atime isn't really reliable as it can be turned off on many file systems that support it to improve performance.

If you wanted to use the WatchService interface for this and the platform(s) your code would run on support it, you could implement your own that looked at access time and fired an event.

This StackOverflow Question demonstrates how to check atime on a file, but again remember it's not really reliable (read the comments on the caveats).

Community
  • 1
  • 1
Brian Roach
  • 76,169
  • 12
  • 136
  • 161