I have a file on my ftp server. I have to check if any file exists in the ftp directory, for every interval of 5 seconds.Could any one let me know, what is the best way to do it(file polling for every 5 secs) through java ?
Welcome to the JavaRanch. It is possible to do FTP using core Java classes. You can get a directory listing by requesting the directory instead of a file name, but then it's up to you to parse the directory listing. The Apache Commons Net package can return a list of files, which would probably be easier to work with.
No I don't have to parse any directory on FTP ...because I have only one directory and one file in it....I have to poll for the file for every 5 seconds....that is I have to look up if file exists or not in the directory for every 5 seconds...and read it if it exists.
If your question is "How do I do X every 5 minutes" and it's only incidental that "X" happens to be looking for a file on an FTP directory, the answer to that is that you use a java.util.Timer object.
Your question was really in two parts and you didn't make it clear which of the two parts you were more interested in.
Vijay G Gandhi
Joined: Jul 10, 2007
First of all ....Thanks for your answer Paul...sorry for the ambiguity in my question....I will try with Timer class but 1) if the file is not uploaded completely on FTP server that is if some thing is writing to the file how would I know if my polling is for every 5 seconds.
2) If I would schedule timer for every 5 seconds....what if I am in the middle of reading first file (say very long file takes 15 seconds to read) and if my timer is polling for the file again after 5 seconds ?
Please let me know if i am clear with my questions...wud appreciate any advice...Thank you...