File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Check folder and start program execution further Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Check folder and start program execution further" Watch "Check folder and start program execution further" New topic
Author

Check folder and start program execution further

Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
I am working on a distributed kind of Project in which i have to call 1 program from another according to requirement.
My problem is that in this whole process i have to check a folder, i.e. i have to keep checking a folder if it's populated with one or more files or not, if yes than call another Jar file
in process, and if not than keep checking it untill it's populated or not. But m unable to do that.. please help me in that issue. Paste some sample code if available.
Thanks.
Abhijeet Ravankar
Ranch Hand

Joined: Mar 15, 2009
Posts: 62
Try to make this multithreaded.


Prashant Hurria
Ranch Hand

Joined: Mar 23, 2009
Posts: 40
If you can use an Opensource Utility use Jnotify it will save you the developement and testing time.
You can make classes implementing the call back interface of JNotify. Whenever a file comes you app gets the notification. Couldn't have been neater no pooling required . JNotify supplies Native files (.dll for windows .so for linux) I have tested it extensivally on Windows and Linux it works pretty well .....

Another option is JPoller :Advantage no Native calls pure java. Disadvantage: It pools based on the polling frequency you set.
http://jpoller.sourceforge.net
http://jnotify.sourceforge.net

If you have any problem which you are not able to solve after help from Web Search lemme know .....

Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Thanks for your precious replies . Well i've solved that problem through a simple method. I have run a infinite loop and am checking the folder if it has some file or not at every 10 minutes. I've used Thread.sleep() for waiting. It was a simple glitch,well i will test it through your methods too , but let me complete this project first . Thanks once again .Cheers
Riyas Hameed
Ranch Hand

Joined: Jan 07, 2012
Posts: 33
Hi All,

My requirement is the same only, what i have to do means I keep on watching the folder in a C: \sourcefolder drive if the folder is updated with new file then I have to transfer the files to server machine .meanwhile at the same I have to find whether the file is fully written , why because some of the process will be writting the files in that folder I have check whether the file is fully written then i have to tarnsfer .i should not transfer the file if its partially written .

I am working on stand alone networking(JAVA) project , I need to transfer files from client to server when ever any new files added to the client folder.

please advise me to solve this.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Check folder and start program execution further
 
Similar Threads
The ServletContext
How heavy is it to run a background process ?
how to do auto-update for a program
problem adding Arrays to an ArrayList in a loop
adding Process into an Array