I have a strange problem:
in src / main / resources I have a file called "template.xlsx".
If I do this:
InputStream is = new ClassPathResource("template.xlsx").getInputStream();
Or that:
InputStream is = ClassLoader.getSystemResourceAsStream("template.xlsx");
Or that:
InputStream is = getClass().getResourceAsStream("/template.xlsx");
When I try to create a book:
Workbook wb = new XSSFWorkbook(is);
I get this error:
java.util.zip.ZipException: invalid block type
BUT, when I get my file as follows:
InputStream is = new FileInputStream("C:/.../src/main/resources/template.xlsx");
It works!
What's wrong? I can not hardcode the full path to the file.
Can someone help me?
thanks
java stream apache-poi
Maxime ARNSTAMM
source share