1. 描述:将代码迁移到maven工程,其中用ZipInputStream读取/src/main/resources下的zip文件时报错:“java.util.zip.ZipException: invalid code lengths set”

代码如下:

ZipInputStream zis = new ZipInputStream(getClass().getResourceAsStream(objectDicFilePath));

zis.getNextEntry();

ObjectInputStream ois = new ObjectInputStream(zis);

2. 原因:maven从resources中读取资源时默认会进行过滤,其中包含了重新编码,因此如果资源文件与maven的编码环境不同时,会导致文件损坏。

3. 解决:

(方案1)在pom.xml中设置filtering为true时则过滤

<filtering>true</filtering>

因此将其置false。

(方案2)或者,将

<encoding>ISO-8859-1</encoding>

改为资源文件的编码格式。

(方案3)把资源文件zip解压后放入resources,我最后这么做的。

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-08-24
  • 2021-10-02
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2021-05-07
相关资源
相似解决方案