Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Appending current date and time to the log file name  RSS feed

 
Sowm Herur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually the requirement is to append the current date and time with the log file name.

To do this we have actually given it this way

try {
if (fos1 == null) {
fos1= new FileOutputStream(new File("ATT_FAILED"+ "_" + new Date().toString().replaceAll(" ","") + ".log"));

System.out.println(fos1);

But it throws a exception saying

[9/3/09 11:18:53:297 IST] 00000034 SystemErr java.io.FileNotFoundException: ATT_FAILED_ThuSep0311:18:53IST2009.log (The parameter is incorrect)

How do i overcome this or is there any other way to append the current date and time ? Please clarify

 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By removing the colons as well. You'd best use a (Simple)DateFormat for turning the date into a string:
Don't forget those single quotes inside the pattern; they make sure that everything between them is treated as literal text.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!