dcsimg
How can I Poll for the arrival of a file at a specified time interval?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shyam_Krishnan
Posted On:   Thursday, July 1, 2004 04:12 AM

Through my application, I need to poll for the arrival of some files in a particular folder. The polling has to be done at a specified time interval. Please suggest any method for doing that using Java.


Thanks,

Shyam

Re: How can I Poll for the arrival of a file at a specified time interval?

Posted By:   Anjani_Kalyan  
Posted On:   Thursday, July 1, 2004 05:41 AM

you can use this




boolean filePresent=false;

int tmpMaxLimit = 0;

while(!filePresent) {

try {

InputStream file = new FileInputStream(fileNeeded);

} catch (FileNotFoundException fnfExp) {

//ignore this as file is not present

}

if(file == null && tmpMaxLimit <= maxLimit) {

Thread.sleep(interval); //interval is in milli seconds

tmpMaxLimit += interval;

}

else {

filePresent = true;

if(tmpMaxLimit >= maxLimit)

reason = "Timeout";

else

reason = "File Present";

}

}



With this code you can run until maxLimit time to check if the file is present.
About | Sitemap | Contact