• Post Reply Bookmark Topic Watch Topic
  • New Topic

writing a temp file  RSS feed

 
rastas biggs
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one give a pointer as to what the best practice is when writing and renaming a file.

I write a file to a directory with a file extention .csv.tmp so a cron job will not ftp my file before it has finished being written, close the writer etc..

now I take my file and rename by removing the .tmp and allowing the cron jopb to ftp.

Now my question is what is the best appraoch to performing this proceedure.

Is it better to use createTempFile() or just get the file and apply indexOf('.') and remove .tmp?

Any advice apprciated

RB
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you'll have a rename at the end either way. I'd probably use File.createTempFile with a meaningful prefix so humans can identify the file if the process fails.

Another trick is to have the job that reads the file actually look for a second file. Write the second file only after the first one is complete, meaning the first one is assured to be closed. The second file can be zero bytes or whatever you like.

Your cron job is probably running some scripting language?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!