Timer in a program, and Deleting a file

I need to set my program to check for files in a directory every 2 seconds and if something is there then I will process it otherwise wait.  This program will basically run forever (or until the computer crashes).

I also need to know how to delete a file in Java.  I am very new so forgive me for asking trivial questions.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Look at java.util.Timer
and new File("path_to_file").delete(); // to delete a file
How about something relatively simple like:

String dfile[];
File dirc=new File(dirname);
while(/* continuecondition */)
{   Thread.sleep(2000);           // delay for 2 seconds
     dfile=dirc.list();                  // get list of files in directory "dirname"
     for(int i=0; i<dfile.length; ++i)
     {   if( /* dfile[i] needs processing */)
         {   // process file

This while loop waits for 2 seconds, gets a list of the files in the directory sepcified for dirc, then checks each one to see if it needs to be processed or not.
Some files returned may not actually need to be processed such as "." and "..".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
So, for /* continuecondition */ you would need to fill in some details.
The while condition controls how long the program runs. You may want to run it for some fixed amount of time (10 hours) or until it receives some signal to stop.
For /* dfile[i] needs processing */ you would presumably fill in some condition based on the file name.

Oh, and to delete a file you can also use a File object:

File df=new File(filename);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.