I use the Apache Commons 1.4.1 library to compress and decompress the ".tar.gz" files.
I am having problems with the last bit - converting TarArchiveInputStream to FileOutputStream .
Oddly enough, it breaks in this line:
FileOutputStream fout = new FileOutputStream(destPath);
destPath is a canonical path file: C: \ Documents and Settings \ Administrator \ My Documents \ JavaWorkspace \ BackupUtility \ untarred \ Test \ subdir \ testinsub.txt
Mistake:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
Any idea what this could be? And why can't he find a way?
I am attaching the whole method below (most of which is taken 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(); }
java apache-commons file-io tar decompression
Redandwhite Jul 11 2018-12-12T00: 00Z
source share