I am working as a trainee in Test Automation. I am working with creating Junit code with Eclipse and run using Eclipse. In that I am retriving the datas from excel sheet usi
I do such a way to ensure to close the excel file input stream, this maybe helps
abstract int workWithWorkBook(Workbook workBook);
protected int doWorkBook(Path excelFile) throws IOException {
File f = excelFile.toFile();
try (FileInputStream excelContent = new FileInputStream(excelFile.toFile())){
POIFSFileSystem fileSystem = new POIFSFileSystem(excelContent);
Workbook workBook = null;
if (f.getName().endsWith("xls")) {
workBook = new HSSFWorkbook(fileSystem);
} else if (f.getName().endsWith("xlsx")) {
workBook = new XSSFWorkbook(excelContent);
}
return workWithWorkBook(workBook);
}catch (Exception e){
e.printStackTrace();
throw e;
}
}
9b9ea92b-5b63-47f9-a865-fd40dd602cd5