I am trying to read an .xlsx file from my resources folder but when I try to create the XSSFWorkbook it gives me the following error:
java.io.IOException: Failed to read zip entry source
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:106)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:342)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:285)
...
Caused by: java.util.zip.ZipException: invalid code lengths set
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
...
The code I currently have simply does this:
public Object prueba() {
InputStream is = this.getClass().getResourceAsStream("/excels/test.xlsx");
XSSFWorkbook workbook = null;
String response = null;
try {
workbook = new XSSFWorkbook(is); <-- Here the error occurs
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
response = row.getCell(9).getRawValue();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
And in debug mode the variable is if it has content
I also added this to my pom.xml
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xlsx</include>
</includes>
</resource>
