Frage

I am trying to write data to excel sheet using Apache POI.I am using TestNG framerwork and eclipse IDE. Program is executing successfully without any error.But when I click refresh on my project source, excel sheet is not coming. Please tell me how will I see my generated excel sheet. My code is as below:

public class Test {
    public static void main(String args[]) {
        try {
            FileOutputStream fos = new FileOutputStream("User.xls");
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet worksheet = workbook.createSheet("worksheet");
            HSSFRow row1 = worksheet.createRow((short) 0);
            HSSFCell cell1 = row1.createCell((short) 0);
            cell1.setCellValue("abc");
            HSSFCell cell2 = row1.createCell((short) 1);
            cell2.setCellValue("123");
            workbook.write(fos);
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
War es hilfreich?

Lösung

Please check your project's root directory. It should be there by default. If you have specified the working directory in your run configuration -> arguments, you should check that folder. Besides, you can always get the complete file path in Java.

System.out.println(new File("User.xls").getAbsolutePath());

Andere Tipps

try this way to create file

FileOutputStream out =
            new FileOutputStream(new File("User.xls"));

This file will be stored in your class directory folder.

Ex: (Test.java is stored in (c://Workspace//src//Test.java) , the file also will store in same path c://Workspace//src//User.xls")

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top