• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create the unique file name?

 
sridevi kumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time when the client programs runs, it has to create a file to log the message. If it creates a file with the name say, "LogMsg", then sometimes from the same machine, if two requests are shooted, then the contents of that file will be overwritten or it can be appended (for each request).
Instead of that, i want to create a file everytime with the "unique name" so that the log message will be there in that file only for that particular request. For each request, i want to create one file with the unique name.
Could anyone tell how to create a unique file name every time?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One solution is to append a random number at the end of the filename like for instance LogMsg563547728 or something like that using Math.random().
Another solution, which in my opinion is the simplest, is to append the current Time in milliseconds to "LogMsg".
"LogMsg"+new Date().getTime().
This way you are sure to get different files every milliseconds
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
sridevi kumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Valentin Crettaz,
Thank you very much...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic