• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

append a file name with timestamp

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to append a file name with time stamp so that every file will have a unique file name. I tried as below:



This works fine as the file name gets appended with 2008-04-07.txt Now I want to add timestamp with it to make it unique. I tried as below:
It is throwing error.
When I try to print the above piece of code, it prints as below:
But it is not allowing me to write a file as with that name filename_2008-04-07 10:48:05.083.txt (The parameter is incorrect) Is it due to the gap between date and time stamp. How do I overcome this? Thanks.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Windows ? In Windows Explorer, try to create a file whose name is the filename you have posted above. What does it say ?
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response. I could finish it as below:



Now I could append the filename with date_time so that it each file name is unique.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gopu Akraju:
Thanks for your response. I could finish it as below:



Now I could append the filename with date_time so that it each file name is unique.


You can use one single method as well:

It will be just a bit more efficient - only one SimpleDateFormat and Date object for each file, as well as no String concatenation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic