Max*_*AMM 11 java stream apache-poi
我有一个奇怪的问题:
在src/main/resources中我有一个"template.xlsx"文件.
如果我这样做:
InputStream is = new ClassPathResource("template.xlsx").getInputStream();
Run Code Online (Sandbox Code Playgroud)
或这个 :
InputStream is = ClassLoader.getSystemResourceAsStream("template.xlsx");
Run Code Online (Sandbox Code Playgroud)
或这个 :
InputStream is = getClass().getResourceAsStream("/template.xlsx");
Run Code Online (Sandbox Code Playgroud)
当我尝试创建工作簿时:
Workbook wb = new XSSFWorkbook(is);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
java.util.zip.ZipException: invalid block type
Run Code Online (Sandbox Code Playgroud)
但是,当我得到这样的文件时:
InputStream is = new FileInputStream("C:/.../src/main/resources/template.xlsx");
Run Code Online (Sandbox Code Playgroud)
有用 !
怎么了 ?我无法将完整路径硬编码到文件中.
有人可以帮我弄这个吗 ?
谢谢
小智 20
我有同样的问题,你可能有maven过滤问题.
此代码从源代码加载文件,未经过滤
InputStream is = new FileInputStream("C:/.../src/main/resources/template.xlsx");
Run Code Online (Sandbox Code Playgroud)
在maven过滤内容后,此代码从目标目录加载文件
InputStream is = getClass().getResourceAsStream("/template.xlsx");
Run Code Online (Sandbox Code Playgroud)
您不应过滤像excel这样的二进制文件,并使用两个互斥的资源集,如本页底部maven resources插件所述
| 归档时间: |
|
| 查看次数: |
7565 次 |
| 最近记录: |