How can we save file with current date?
Date date11 = Calendar.getInstance().getTime();
DateFormat formatter =new SimpleDateFormat("d/M/yyyy");
String date1 =formatter.format(date11);
FileWriter fw = new FileWriter("C:\\InjectionExcel"+ date1 +".csv");
date1 given is current date. But this code is not working. Where am I mistaking?
A file name can’t contain any of the following characters in Windows:
Your problem is caused by attempting to use
/as file name. It will be interpreted as path separator. For example, if the current day is 23 and the directoryC:\InjectionExcel23does not exist, then you will get something like the following exception (which you should initially have reported in your question!):Unrelated to the concrete problem, the way how you created the today’s date is clumsy. You’re generating all that unnecessary
Calendaroverhead. Just usenew Date().