Auto detection
Hello,
I have a java application that takes the name of a file as a command line argument and then works on it. My new requirement is to make the application more responsive in that it should automatically detect the file if it is dropped into a folder. The system is running on windows XP.
So in essence,
The java application should detect the new file, extract the file name and work on it.
Any suggestions and ideas would be really appreciated.
Many thanks
[498 byte] By [
Lexus316a] at [2007-11-26 16:03:47]

you need a thread running that continuosly checks the target directory for new files appearing. there isn't a FileListener or anything handy, nor is there any native code that will do this on most platforms (BeOS is an exception, but the JVM for BeOS is somewhat lacking, apparently)
You can create a schedule job (windows) that calls a Java program from time to time to check if a new file is there (checking it's date for instance or creating a control file). I think this approach is better than having a thread continuously.regards,Manuel Leiria
> You can create a schedule job (windows) that calls a
> Java program from time to time to check if a new file
> is there (checking it's date for instance or creating
> a control file). I think this approach is better than
> having a thread continuously.
>
> regards,
>
> Manuel Leiria
possibly a better approach, yes.
this of course couples you to the platform but in reality that's rarely the problem people think it will be. but there are other reasons not to use scheduled tasks, cron jobs etc, for instance, if you want to monitor and manage the jobs through java. another consideration is how often the java code will come into play. there's little point closing down and re-starting JVMs every few seconds, the expense is too great. may as well just leave a thread running
> The current requirement is to run the app once an> hour. This interval could increase but there is zero> to little chance that it would decrease.how long does a run take? a scheduled task or cron job might be better, but it involves extra management
> Manuel,
>
> I didnt quite follow what you were saying. Could you
> elaborate plz?
In Windows -> Control Panel you have something called Scheduled Tasks where you can assign a program and tell at what times it should be executed, so, create a task to call your Java program from hour to hour.
regards,
Manuel Leiria