Hi, I am finding difficulty to read a file created dynamically with the time stamp. Here is the scenario: I am having a directory called C:/infiles. The data files from other systems (different group) will be written to this directory. The format of the file name will be develop_in_ [timestamp].dat ie., develop_in_20030726122423.dat. They will be dumping the latest files every time interval say 30 mts or so.. with the latest time stamp. I need to read the file and change the name as PROCESSED_develop_in_20030726122423.dat, and update the database with this information. How can i read the file as the name is not static (file name changes with each time stamp and i cannot figure out the time stamp). Please suggest me how can i achieve this? This is very crucial part of my project.
Check out the java.io.File javadoc; particularly, look at the listFiles method. You simply need to write a Filename filter to get this to work:
That will return all the files in the directory that start with "develop_in_". If you need to know the actual timestamp used, you can, of course, parse it from the individual files' names. [ July 28, 2003: Message edited by: Joel McNary ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
We've had some other discussions about this with FTP and other processes on the same machine ... A file may appear in the list as soon as the other program or system opens it to write it. And it may not yet be complete and closed and ready to read. Be prepared to handle an open failure, maybe by waiting until the next directory sweep. Another common trick is for the other system to write two files - the one you really want plus a second dummy file. When the dummy file exists, you know the real file is closed and ready to read.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
As the File to be processed will be in the format "develop_in_XXXX", use java.io.File.List() for getting all files in c:\inFiles, and calculate the timestamp of every file starting with "develop_in_" using String.substring(11) (11 being length of "develop_in_" ) and converting the substring to Integer. Process the file with least TimeStamp first and rename it later.