Jak rozpakować plik TAR przy użyciu Apache Commons
Używam biblioteki Apache Commons 1.4.1 do kompresji i dekompresji".tar.gz"
pliki.
Mam problem z ostatnim bitem - konwersja aTarArchiveInputStream
w aFileOutputStream
.
Co dziwne, w tej linii łamie się:
FileOutputStream fout = new FileOutputStream(destPath);
destPath
to plik z kanoniczną ścieżką: C: Dokumenty i ustawienia Administrator Moje dokumenty JavaWorkspace BackupUtred nieredagowany Subdir directoryub.txt
Wystąpił błąd:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
Jakiś pomysł, co to może być? I dlaczego nie jest w stanie znaleźć ścieżki?
Dołączam całą poniższą metodę (większość z nich jest usunięta ztutaj).
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();
}