0

I am working on report generation, for generating 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());
}


wd.write_xls(Auth,"E:\\Automation\\USP_Automation_Main\\Report\\"+ct.getCurrentTime()+"_report.xlsx");

ERROR:-

java.io.FileNotFoundException: E:\Automation\USP_Automation_Main\Report\2015.02.10_12:18:41_report.xlsx (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");
           System.out.print("\t"+filename+"\t"+tabname+"\t"+col+input.length+"col"+col+"\n");
           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++)
                {                  
                row1.createCell(j).setCellValue(input[i][j]);
                }
                cnt++;
            }
                workbook.write(out);
                out.close();
                System.out.println("report genrated..");
            } catch (Exception e) {
                e.printStackTrace();
            }
        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
  • 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
0

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

2015.02.10_12:18:41_report.xlsx

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.

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.