Java:Extract .gz:错误:找不到流签名的Archiver

Pat*_*tty 2 java compression gzip

我正在开发一个项目,我必须提取一个.gz,里面有一个文本格式的日志文件.我正在尝试这段代码:

public void extractFile(String sourceFilePath) {
    // Untar....

    System.out.println("\n\nextracting file ............... ");

    File sourceFile = new File(sourceFilePath);

    //create the directory to download
    createFile("/home/myname/workspace/log-monitor/target/classes/extractDir");

    File destDir = new File("/home/myname/workspace/log-monitor/target/classes/extractDir");

    Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
    try {
        archiver.extract(sourceFile, destDir);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    }

}
Run Code Online (Sandbox Code Playgroud)

我收到错误:

java.io.IOException: org.apache.commons.compress.archivers.ArchiveException: No Archiver found for the stream signature
Run Code Online (Sandbox Code Playgroud)

进口:

 import org.rauschig.jarchivelib.*;
Run Code Online (Sandbox Code Playgroud)

并在POM中添加了这个:

<dependency>
<groupId>org.rauschig</groupId>
<artifactId>jarchivelib</artifactId>
<version>0.3.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我的是CentOS OS.并使用jdk1.7.

有关更多信息,我试过:

 Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);

 ArchiverFactory.createArchiver("gz");
Run Code Online (Sandbox Code Playgroud)

他们都没有工作.

任何人都可以帮忙.我确定它是关于格式化但不知道如何为.gz文件.

提前致谢.

Bar*_*log 7

也许这会有所帮助:

File a = new File("data/readme.txt.gz");
File o = new File("data/");
Compressor compressor = CompressorFactory.createCompressor(a);
try {
    compressor.decompress(a, o);
} catch (IOException ex) {
    ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)