I am working on report generation. For generation I need date&time[time stamp] telling when the report is generated. For this purpose I have created a method which returns formatted date time values such that I can give the name to excel file.
I am getting error at report generation. My code is as follows:

public class Currenttime {

public String getCurrentTime()
    return new SimpleDateFormat("yyyy.MM.dd_HH:mm:ss").format(Calendar.getInstance().getTime());



(The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileOutputStream.open(Native Method)

Complete code for write xlsx:

public String[][] write_xls(String[][] input,String filename,String tabname,int col) {
           System.out.println("input data lenght"+input.length);

           try {
               File excel = new File("E:\\output.xlsx");
               XSSFWorkbook workbook = new XSSFWorkbook();
               XSSFSheet sheet= workbook.createSheet(tabname);
               FileOutputStream out = new FileOutputStream(filename);
               int cnt=0;
               int inc = 1;
               for(int i=0;i<input.length;i++)
                    XSSFRow row1 = sheet.createRow(cnt);

                    for(int j=0;j<col;j++)
                    System.out.println("report genrated..");
               } catch (Exception e) {
            return null;
  • Please share your full code. This code it not enough to write data in excel. – Helping Hands Feb 10 '15 at 8:18
  • 1
    Do you have local developers near to you? I would first contact them with issues like this. They should be able to resolve basic programming issues faster for you :) – Niels van Reijmersdal Feb 10 '15 at 10:58

Your filename is illegal, colon : is not allowed in files names.


Also see: https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names

I would replace getCurrentTime() with a timestamp or a GUID if the name needs to be unique. If you need the date remove the illegal characters from your time formatter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.