Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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

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.
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.

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
jQuery in Action, 3rd edition