I'm using the Apache Commons 1.4.1 library to compress and uncompress ".tar.gz"
files.
I'm having trouble with the last bit -- converting a TarArchiveInputStream
into a FileOutputStream
.
Oddly enough, it's breaking on this line:
FileOutputStream fout = new FileOutputStream(destPath);
destPath
is a File with a Canonical path of: C:Documents and SettingsAdministratorMy DocumentsJavaWorkspaceBackupUtilityuntarredTestsubdirestinsub.txt
Error produced:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
Any idea what it could be? And why is it not able to find the path?
I'm attaching the whole method below (most of which is lifted from here).
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();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…