Como descompactar um arquivo TAR usando o Apache Commons
Estou usando a biblioteca Apache Commons 1.4.1 para compactar e descompactar".tar.gz"
arquivos.
Estou tendo problemas com o último bit - convertendo umTarArchiveInputStream
dentro deFileOutputStream
.
Curiosamente, está quebrando nesta linha:
FileOutputStream fout = new FileOutputStream(destPath);
destPath
é um arquivo com um caminho canônico de: C: \ Documents and Settings \ Administrador \ Meus Documentos \ JavaWorkspace \ BackupUtility \ untarred \ Test \ subdir \ testinsub.txt
Erro produzido:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
Alguma ideia do que poderia ser? E por que não é capaz de encontrar o caminho?
Eu estou anexando todo o método abaixo (a maioria dos quais é levantada deAqui).
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();
}