Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading a dynamic file...

 
satya kiran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks in advance for your help,
kiran
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic