Как распаковать файл TAR с помощью Apache Commons

Я использую библиотеку Apache Commons 1.4.1 для сжатия и распаковки ".tar.gz"файлов.

У меня возникли проблемы с преобразованием последнего бита --из TarArchiveInputStreamв FileOutputStream.

Как ни странно, он обрывается на этой строке:

FileOutputStream fout = new FileOutputStream(destPath);

destPathэто файл с каноническим путем :C :\Documents and Settings\Administrator\My Documents\JavaWorkspace\BackupUtility\untarred\Test\subdir\testinsub.txt

Возникла ошибка:

Exception in thread "main" java.io.IOException: The system cannot find the path specified

Любая идея, что это может быть? И почему он не может найти путь?

Я прикрепляю весь метод ниже (, большая часть которого взята из здесь).

private void untar(File dest) throws IOException {
    dest.mkdir();
    TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
    // tarIn is a TarArchiveInputStream
    while (tarEntry != null) {// create a file with the same name as the tarEntry
        File destPath = new File(dest.toString() + System.getProperty("file.separator") + tarEntry.getName());
        System.out.println("working: " + destPath.getCanonicalPath());
        if (tarEntry.isDirectory()) {
            destPath.mkdirs();
        } else {
            destPath.createNewFile();
            FileOutputStream fout = new FileOutputStream(destPath);
            tarIn.read(new byte[(int) tarEntry.getSize()]);
            fout.close();
        }
        tarEntry = tarIn.getNextTarEntry();
    }
    tarIn.close();
}

6
задан tommybee 23 May 2017 в 19:46
поделиться