15

我正在尝试使用从 apache commons compress 示例网页获得的以下代码来使用 SevenZ 类创建一个 zip 文件,希望它比普通的 java zip 压缩更快。这就是我的代码的样子

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream("c:/temp/test.txt"));

    SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("c:/temp/7ztest.zip"));
    SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(new File("c:/temp/test.txt"),"blah.txt");
    sevenZOutput.putArchiveEntry(entry);
    byte[] buffer = new byte[1024];
    int len;
    while ((len = instream.read(buffer)) > 0) {sevenZOutput.write(buffer, 0, len);}

    sevenZOutput.closeArchiveEntry();
    sevenZOutput.close();
    instream.close();
    }catch(IOException ioe) {
        System.out.println(ioe.toString());

    }
}

我收到了这个看起来很不相关的错误

java.lang.J9VMInternals.verifyImpl(Native Method) at java.lang.J9VMInternals.verify(J9VMInternals.java:93) 的线程“main”java.lang.NoClassDefFoundError 中的异常:org.tukaani.xz.FilterOptions

我有导入的 apache 包

导入 org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;导入 org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;

但不确定 org.tukaani.xz.FilterOptions 是什么,它看起来不像是 apace commons compress 的一部分。有什么想法吗?

4

1 回答 1

29

如Apache Commons的“已知限制”页面所述:

“该格式需要其他可选的XZ for Java库。”

对于其他格式,此依赖项是可选的,但对于 7zip,您需要它。

<dependency>
  <groupId>org.tukaani</groupId>
  <artifactId>xz</artifactId>
  <version>1.5</version>
</dependency>
于 2015-02-02T12:14:04.697 回答