-1

I tried to read an excel file in Anylogic software(is based on Eclipse).

I use Poi to read the file but i get java.io.FileNotFoundException when I launch the program.

Can you help me plese?

This is the code:

FileInputStream fileInputStream = new FileInputStream("C://Users/leonardo/Desktop/ListaAttesa.xlsx");
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
leovall93
  • 1
  • 1

2 Answers2

1

You can verify that your file exists at that place via

if(!new File("C://Users/leonardo/Desktop/ListaAttesa.xlsx").exists()) {
    throw new IllegalStateException("File not found!");
}

And as pointed out in the comments, for a .xlsx file you should use XSSFWorkbook, not HSSFWorkbook.

centic
  • 15,565
  • 9
  • 68
  • 125
1

That error has nothing to do with the file itself or the way you are trying to read it. It just tells you that at the given path ("C://Users/leonardo/Desktop/ListaAttesa.xlsx" in your case) the file does not exist. I wonder why you have a double slash behind C: and guess that this is the error in this case. BTW: You might be interested in the fact that there is an excel file block in the connectivity group that can be dragged into the workspace and then be used programmatically. But I dont know your use case so I cannot tell you if it is appropriate in your case.

T_D
  • 1,688
  • 1
  • 17
  • 28